/// <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); }
/// <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) { bool canRemove = true; // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode); canRemove = NodeGraphEditor.GetEditor(node.graph, NodeEditorWindow.current).CanRemove(node); } // Add actions to any number of selected nodes menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes); menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes); if (canRemove) { menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); } else { menu.AddItem(new GUIContent("Remove"), false, null); } // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddCustomContextMenuItems(node); } }
/// <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) { // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is BlackboardObject) { BlackboardObject bbo = Selection.activeObject as BlackboardObject; menu.AddItem(new GUIContent("Rename"), false, () => { if (BlackboardNodeEditor.current != null) { RenamePopup.Show(Selection.activeObject, BlackboardNodeEditor.current.GetWidth()); } else { RenamePopup.Show(Selection.activeObject); } }); } menu.AddItem(new GUIContent("Remove"), false, () => { BlackboardNodeEditor.current.RemoveSelectedValue(); }); // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is BlackboardObject) { BlackboardObject bbo = Selection.activeObject as BlackboardObject; menu.AddCustomContextMenuItems(bbo); } }
/// <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) { // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode); } // Add actions to any number of selected nodes menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddCustomContextMenuItems(node); } }
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); }
/// <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) { bool canRemove = true; // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddItem(new GUIContent("Edit Script"), false, () => { string assetPath = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(target)); AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath <MonoScript>(assetPath)); }); menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode); canRemove = NodeGraphEditor.GetEditor(node.graph, NodeEditorWindow.current).CanRemove(node); } // Add actions to any number of selected nodes menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes); menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes); if (canRemove) { menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); } else { menu.AddItem(new GUIContent("Remove"), false, null); } // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddCustomContextMenuItems(node); } }
/// <summary> /// Add items for the context menu when right-clicking this node. /// Override to add custom menu items. /// </summary> /// <param name="menu"></param> /// <param name="compatibleType">Use it to filter only nodes with ports value type, compatible with this type</param> /// <param name="direction">Direction of the compatiblity</param> public virtual void AddContextMenuItems(GenericMenu menu, Type compatibleType = null, XNode.NodePort.IO direction = XNode.NodePort.IO.Input) { Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition); Type[] nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray(); if (compatibleType != null && NodeEditorPreferences.GetSettings().createFilter) { nodeTypes = NodeEditorUtilities.GetCompatibleNodesTypes(NodeEditorReflection.nodeTypes, compatibleType, direction).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); }
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()); }