/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary> public virtual void AddContextMenuItems(GenericMenu menu) { Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); for (int i = 0; i < NodeEditorReflection.nodeTypes.Length; i++) { Type type = NodeEditorReflection.nodeTypes[i]; //Get node context menu path string path = GetNodeMenuName(type); if (string.IsNullOrEmpty(path)) { continue; } menu.AddItem(new GUIContent(path), false, () => { XNode.Node node = CreateNode(type, pos); NodeEditorWindow.current.AutoConnect(node); }); } menu.AddSeparator(""); if (NodeEditorWindow.copyBuffer != null && NodeEditorWindow.copyBuffer.Length > 0) { menu.AddItem(new GUIContent("Paste"), false, () => NodeEditorWindow.current.PasteNodes(pos)); } else { menu.AddDisabledItem(new GUIContent("Paste")); } menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorReflection.OpenPreferences()); menu.AddCustomContextMenuItems(target); }
public override void OnInspectorGUI() { if (sceneGraph.graph == null) { if (GUILayout.Button("New graph", GUILayout.Height(40))) { if (graphType == null) { Type[] graphTypes = NodeEditorReflection.GetDerivedTypes(typeof(NodeGraph)); GenericMenu menu = new GenericMenu(); for (int i = 0; i < graphTypes.Length; i++) { Type graphType = graphTypes[i]; menu.AddItem(new GUIContent(graphType.Name), false, () => CreateGraph(graphType)); } menu.ShowAsContext(); } else { CreateGraph(graphType); } } } else { if (GUILayout.Button("Open graph", GUILayout.Height(40))) { NodeEditorWindow.Open(sceneGraph.graph); } if (removeSafely) { GUILayout.BeginHorizontal(); GUILayout.Label("Really remove graph?"); GUI.color = new Color(1, 0.8f, 0.8f); if (GUILayout.Button("Remove")) { removeSafely = false; Undo.RecordObject(sceneGraph, "Removed graph"); sceneGraph.graph = null; } GUI.color = Color.white; if (GUILayout.Button("Cancel")) { removeSafely = false; } GUILayout.EndHorizontal(); } else { GUI.color = new Color(1, 0.8f, 0.8f); if (GUILayout.Button("Remove graph")) { removeSafely = true; } GUI.color = Color.white; } } base.OnInspectorGUI(); }
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary> public virtual void AddContextMenuItems(GenericMenu menu) { Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); var nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray(); for (int i = 0; i < nodeTypes.Length; i++) { Type type = nodeTypes[i]; //Get node context menu path string path = GetNodeMenuName(type); if (string.IsNullOrEmpty(path)) { continue; } // Check if user is allowed to add more of given node type XNode.Node.DisallowMultipleNodesAttribute disallowAttrib; bool disallowed = false; if (NodeEditorUtilities.GetAttrib(type, out disallowAttrib)) { int typeCount = target.nodes.Count(x => x.GetType() == type); if (typeCount >= disallowAttrib.max) { disallowed = true; } } if (window.graph is DialogGraph) { } // Add node entry to context menu if (disallowed) { menu.AddItem(new GUIContent(path), false, null); } else { menu.AddItem(new GUIContent(path), false, () => { XNode.Node node = CreateNode(type, pos); NodeEditorWindow.current.AutoConnect(node); }); } } menu.AddSeparator(""); if (NodeEditorWindow.copyBuffer != null && NodeEditorWindow.copyBuffer.Length > 0) { menu.AddItem(new GUIContent("Paste"), false, () => NodeEditorWindow.current.PasteNodes(pos)); } else { menu.AddDisabledItem(new GUIContent("Paste")); } menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorReflection.OpenPreferences()); menu.AddCustomContextMenuItems(target); }