From 2d91e45dba95cba5ede5263b5e49da78ab2cc826 Mon Sep 17 00:00:00 2001 From: juliocp Date: Wed, 7 Oct 2020 19:12:35 -0300 Subject: [PATCH] Added parameter to AddContexMenuItens - Added parameters to get contextMenu with compatibles node filter. These parameters are auto-filled and do not interfere with the standard operation of this function. > Param: Type compatibleType: Use it to filter only nodes with ports value type, compatible with this type: Default null. > Param: NodePor.IO: Direction of the compatiblity: (Default Input) --- Scripts/Editor/NodeGraphEditor.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 8b671e2..b7ed32d 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -64,11 +64,24 @@ namespace XNodeEditor return 0; } - /// Add items for the context menu when right-clicking this node. Override to add custom menu items. - public virtual void AddContextMenuItems(GenericMenu menu) + /// + /// Add items for the context menu when right-clicking this node. + /// Override to add custom menu items. + /// + /// + /// Use it to filter only nodes with ports value type, compatible with this type + /// Direction of the compatiblity + 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); - var nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray(); + + Type[] nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray(); + + if (compatibleType != null) + { + nodeTypes = NodeEditorUtilities.GetCompatibleNodesTypes(NodeEditorReflection.nodeTypes, compatibleType, direction).ToArray(); + } + for (int i = 0; i < nodeTypes.Length; i++) { Type type = nodeTypes[i]; @@ -101,6 +114,7 @@ namespace XNodeEditor menu.AddCustomContextMenuItems(target); } + /// Returned gradient is used to color noodles /// The output this noodle comes from. Never null. /// The output this noodle comes from. Can be null if we are dragging the noodle.