From ada6d85c51d4634f25f14d9fbf4eeac87103cc0d Mon Sep 17 00:00:00 2001 From: Emre Dogan <48212096+EmreDogann@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:00:53 +0100 Subject: [PATCH] Fixed flow of graphFindAttempted in NodeEditorGUI.cs. Improved handling of drag threshold. --- Scripts/Editor/NodeEditorAction.cs | 17 ++++++++++------- Scripts/Editor/NodeEditorGUI.cs | 11 ++++++++--- Scripts/Editor/NodeEditorWindow.cs | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 1ee113f..b8ef971 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -79,7 +79,8 @@ namespace XNodeEditor private Rect selectionBox; private bool isDoubleClick; private Vector2 lastMousePosition; - private float dragThreshold = 1f; + private Vector2 lastMouseDownPosition; + private readonly float dragThreshold = 5f; public void Controls() { @@ -242,17 +243,19 @@ namespace XNodeEditor } else if (e.button == 1 || e.button == 2) { - //check drag threshold for larger screens - // if (e.delta.magnitude > dragThreshold) - // { - // } - isPanning = true; - panOffset += e.delta * zoom; + // Check drag threshold for larger screens + if (isPanning || (lastMouseDownPosition - e.mousePosition).sqrMagnitude > + dragThreshold * dragThreshold) + { + isPanning = true; + panOffset += e.delta * zoom; + } } break; case EventType.MouseDown: Repaint(); + lastMouseDownPosition = e.mousePosition; if (e.button == 0) { draggedOutputReroutes.Clear(); diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 0e91de1..a3f7c07 100755 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -30,10 +30,15 @@ namespace XNodeEditor { Event e = Event.current; Matrix4x4 m = GUI.matrix; - if (graph == null && !graphFindAttempted) + if (graph == null) { - graphFindAttempted = true; - if (!OnOpen(graphInstanceID, 0)) + if (!graphFindAttempted && !OnOpen(graphInstanceID, 0)) + { + graphFindAttempted = true; + return; + } + + if (graphFindAttempted) { return; } diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index d6075d8..62f85bf 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -142,7 +142,7 @@ namespace XNodeEditor } } - dragThreshold = Math.Max(1f, Screen.width / 1000f); + // dragThreshold = Math.Max(1f, Screen.width / 1000f); } private void OnLostFocus()