/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary> public override void AddContextMenuItems(GenericMenu menu) { menu.AddItem(new GUIContent("Init State Machines"), false, () => (target as StateMachineGraph).parentMachine.InitStateMachines(false)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Expand All"), false, () => (target as StateMachineGraph).ToggleExpandAll(false)); menu.AddItem(new GUIContent("Collapse All"), false, () => (target as StateMachineGraph).ToggleExpandAll(true)); menu.AddSeparator(""); 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; } } // 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); }
// Override method to check if a node of type EntryNode already exists in the graph, making the user unable to add // multiple entry nodes to the same graph via the node editor. // FIXME change xNode to make this easier. Most of this method is copied from the source code while I only need to change the logic that adds the items to the menu. public override void AddContextMenuItems(GenericMenu menu) { var pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); var graph = target as DialogueGraph; foreach (var type in NodeEditorReflection.nodeTypes) { //Get node context menu path var path = GetNodeMenuName(type); if (string.IsNullOrEmpty(path)) { continue; } // Allow only one node of type EntryNode per graph if (type == typeof(EntryNode) && graph.HasEntryNode()) { menu.AddDisabledItem(new GUIContent(path)); } else { var type1 = type; menu.AddItem(new GUIContent(path), false, () => { var node = CreateNode(type1, pos); NodeEditorWindow.current.AutoConnect(node); }); } } if (NodeEditorReflection.nodeTypes.Length > 0) { 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 AddContextMenuItems(GenericMenu menu) { Type[] types = new Type[3] { typeof(Dialogue), typeof(Answer), typeof(Group) }; Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); for (int i = 0; i < types.Length; i++) { Type type = types[i]; menu.AddItem(new GUIContent(type.Name), false, () => { XNode.Node node = CreateNode(type, pos); NodeEditorWindow.current.AutoConnect(node); }); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorReflection.OpenPreferences()); menu.AddCustomContextMenuItems(target); }
public override void AddContextMenuItems(GenericMenu menu) { //base.AddContextMenuItems(menu); Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); menu.AddItem(new GUIContent("Add/Global"), false, () => CreateRootDataView(pos)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Refresh"), false, () => SynchronizeGraphAndScene()); menu.AddItem(new GUIContent("Delete unused ports"), false, () => DeleteUnusedPorts()); 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); //menu.AddItem(new GUIContent("Update"), false, () => FrameUtilites.PushGraphsToFrames()); }