From 1fff90cbf2c745f4c35bd65ca1e4be341521bc5b Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Wed, 28 Mar 2018 00:55:53 +0200 Subject: [PATCH] Added 'Clear Connections' right-click option for NodePorts --- Scripts/Editor/NodeEditorAction.cs | 2 ++ Scripts/Editor/NodeEditorGUI.cs | 8 ++++++++ Scripts/Node.cs | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 7b43574..c1f7a40 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -159,6 +159,8 @@ namespace XNodeEditor { currentActivity = NodeActivity.Idle; } else if (e.button == 1) { if (!isPanning) { + if (IsHoveringPort) + ShowPortContextMenu(hoveredPort); if (IsHoveringNode && IsHoveringTitle(hoveredNode)) { if (!Selection.Contains(hoveredNode)) SelectNode(hoveredNode, false); ShowNodeContextMenu(); diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 4db162b..f5fd919 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -87,6 +87,14 @@ namespace XNodeEditor { return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width)); } + /// Show right-click context menu for hovered port + void ShowPortContextMenu(XNode.NodePort hoveredPort) { + GenericMenu contextMenu = new GenericMenu(); + contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections()); + contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); + AssetDatabase.SaveAssets(); + } + /// Show right-click context menu for selected nodes public void ShowNodeContextMenu() { GenericMenu contextMenu = new GenericMenu(); diff --git a/Scripts/Node.cs b/Scripts/Node.cs index ddc43ea..099c56e 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -127,7 +127,7 @@ namespace XNode { } /// Removes all instance ports from the node - [ContextMenu("Clear instance ports")] + [ContextMenu("Clear Instance Ports")] public void ClearInstancePorts() { List instancePorts = new List(InstancePorts); foreach (NodePort port in instancePorts) {