From 37d82ad2157ddd3122ec52d9c3e9d537f15a6c16 Mon Sep 17 00:00:00 2001 From: juliocp Date: Wed, 7 Oct 2020 19:31:07 -0300 Subject: [PATCH] Added DragToCreate compatible filter - Added preference to filter the nodes from the draggable context menu, to show only nodes that have ports compatible with the dragged port - Minor modification in NodeEditorActions, to allow the filter - Minor modification in NodeGraphEditor to use or not the filter, based in preferences --- Scripts/Editor/NodeEditorAction.cs | 2 +- Scripts/Editor/NodeEditorPreferences.cs | 11 +++++++++++ Scripts/Editor/NodeGraphEditor.cs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 738a602..438299e 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -290,7 +290,7 @@ namespace XNodeEditor else if (draggedOutputTarget == null && NodeEditorPreferences.GetSettings().dragToCreate && autoConnectOutput != null) { GenericMenu menu = new GenericMenu(); - graphEditor.AddContextMenuItems(menu); + graphEditor.AddContextMenuItems(menu, draggedOutput.ValueType); menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); } //Release dragged connection diff --git a/Scripts/Editor/NodeEditorPreferences.cs b/Scripts/Editor/NodeEditorPreferences.cs index d16dfd0..73f2552 100644 --- a/Scripts/Editor/NodeEditorPreferences.cs +++ b/Scripts/Editor/NodeEditorPreferences.cs @@ -37,6 +37,7 @@ namespace XNodeEditor { public bool autoSave = true; public bool openOnCreate = true; public bool dragToCreate = true; + public bool dragToCreateFilter = true; public bool zoomToMouse = true; public bool portTooltips = true; [SerializeField] private string typeColorsData = ""; @@ -166,6 +167,16 @@ namespace XNodeEditor { settings.noodleStroke = (NoodleStroke) EditorGUILayout.EnumPopup("Noodle stroke", (Enum) settings.noodleStroke); settings.portTooltips = EditorGUILayout.Toggle("Port Tooltips", settings.portTooltips); settings.dragToCreate = EditorGUILayout.Toggle(new GUIContent("Drag to Create", "Drag a port connection anywhere on the grid to create and connect a node"), settings.dragToCreate); + + //Drag to Create Filter + int oldIndent = EditorGUI.indentLevel; + EditorGUI.indentLevel = oldIndent + 1; + GUI.enabled = settings.dragToCreate; + settings.dragToCreateFilter = EditorGUILayout.Toggle(new GUIContent("Filter", "Only show nodes that are compatible with the dragged port"), settings.dragToCreateFilter); + GUI.enabled = true; + EditorGUI.indentLevel = oldIndent; + + //END if (GUI.changed) { SavePrefs(key, settings); NodeEditorWindow.RepaintAll(); diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index b7ed32d..5890309 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -77,7 +77,7 @@ namespace XNodeEditor Type[] nodeTypes = NodeEditorReflection.nodeTypes.OrderBy(type => GetNodeMenuOrder(type)).ToArray(); - if (compatibleType != null) + if (compatibleType != null && NodeEditorPreferences.GetSettings().dragToCreateFilter) { nodeTypes = NodeEditorUtilities.GetCompatibleNodesTypes(NodeEditorReflection.nodeTypes, compatibleType, direction).ToArray(); }