diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index f3ebde4..5add067 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -22,11 +22,12 @@ namespace XNodeEditor { [NonSerialized] private List draggedOutputReroutes = new List(); private RerouteReference hoveredReroute = new RerouteReference(); private List selectedReroutes = new List(); - private Rect nodeRects; + private Rect nodeRects; // Is this used? private Vector2 dragBoxStart; private UnityEngine.Object[] preBoxSelection; private RerouteReference[] preBoxSelectionReroute; private Rect selectionBox; + private bool isDoubleClick = false; private struct RerouteReference { public XNode.NodePort port; @@ -172,6 +173,10 @@ namespace XNodeEditor { SelectNode(hoveredNode, e.control || e.shift); if (!e.control && !e.shift) selectedReroutes.Clear(); } else if (e.control || e.shift) DeselectNode(hoveredNode); + + // Cache double click state, but only act on it in MouseUp - Except ClickCount only works in mouseDown. + isDoubleClick = ( e.clickCount == 2 ); + e.Use(); currentActivity = NodeActivity.HoldNode; } else if (IsHoveringReroute) { @@ -239,6 +244,13 @@ namespace XNodeEditor { if (currentActivity == NodeActivity.HoldNode && !(e.control || e.shift)) { selectedReroutes.Clear(); SelectNode(hoveredNode, false); + + // Double click to center node + if ( isDoubleClick ) + { + Vector2 nodeDimension = nodeSizes.ContainsKey( hoveredNode ) ? nodeSizes[ hoveredNode ] / 2 : new Vector2(0f, 0f); + panOffset = -hoveredNode.position - nodeDimension; + } } // If click reroute, select it. @@ -273,6 +285,8 @@ namespace XNodeEditor { } isPanning = false; } + // Reset DoubleClick + isDoubleClick = false; break; case EventType.KeyDown: if (EditorGUIUtility.editingTextField) break;