mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 06:29:03 +08:00
Context menu limited to graph background and node headers
This commit is contained in:
parent
1ddfdeb1d3
commit
dabd55cf49
@ -103,7 +103,13 @@ namespace XNodeEditor {
|
|||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
} else if (e.button == 1) {
|
} else if (e.button == 1) {
|
||||||
if (!isPanning) ShowContextMenu();
|
if (!isPanning) {
|
||||||
|
if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
||||||
|
ShowNodeContextMenu(hoveredNode);
|
||||||
|
} else if (!IsHoveringNode) {
|
||||||
|
ShowGraphContextMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
isPanning = false;
|
isPanning = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -71,27 +71,29 @@ namespace XNodeEditor {
|
|||||||
return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width));
|
return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Show right-click context menu </summary>
|
/// <summary> Show right-click context menu for a node </summary>
|
||||||
public void ShowContextMenu() {
|
public void ShowNodeContextMenu(Node node) {
|
||||||
GenericMenu contextMenu = new GenericMenu();
|
GenericMenu contextMenu = new GenericMenu();
|
||||||
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
||||||
|
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
|
||||||
|
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||||
|
}
|
||||||
|
|
||||||
if (hoveredNode != null) {
|
/// <summary> Show right-click context menu for current graph </summary>
|
||||||
Node node = hoveredNode;
|
void ShowGraphContextMenu() {
|
||||||
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
|
GenericMenu contextMenu = new GenericMenu();
|
||||||
} else {
|
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
|
||||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||||
Type type = nodeTypes[i];
|
Type type = nodeTypes[i];
|
||||||
|
|
||||||
string name = nodeTypes[i].ToString().Replace('.', '/');
|
string name = nodeTypes[i].ToString().Replace('.', '/');
|
||||||
Node.CreateNodeMenuAttribute attrib;
|
Node.CreateNodeMenuAttribute attrib;
|
||||||
if (NodeEditorUtilities.GetAttrib(type, out attrib)) {
|
if (NodeEditorUtilities.GetAttrib(type, out attrib)) {
|
||||||
name = attrib.menuName;
|
name = attrib.menuName;
|
||||||
}
|
|
||||||
contextMenu.AddItem(new GUIContent(name), false, () => {
|
|
||||||
CreateNode(type, pos);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
contextMenu.AddItem(new GUIContent(name), false, () => {
|
||||||
|
CreateNode(type, pos);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user