1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

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)
This commit is contained in:
juliocp 2020-10-07 19:12:35 -03:00
parent 1b32e2ec03
commit 2d91e45dba

View File

@ -64,11 +64,24 @@ namespace XNodeEditor
return 0;
}
/// <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)
/// <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);
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);
}
/// <summary> Returned gradient is used to color noodles </summary>
/// <param name="output"> The output this noodle comes from. Never null. </param>
/// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param>