From cf59838dd0be5ec3a89631609e388d6a77839225 Mon Sep 17 00:00:00 2001 From: Icarus <1375400884@qq.com> Date: Mon, 9 Dec 2019 11:11:47 +0800 Subject: [PATCH] !O --- Scripts/Editor/NodeEditorAction.cs | 19 ++++++++++--------- Scripts/Editor/NodeEditorWindow.cs | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index c919c9b..63e1439 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -32,8 +32,14 @@ namespace XNodeEditor { private Rect selectionBox; private bool isDoubleClick = false; private Vector2 lastMousePosition; + private MenuPopupWindow _menuPopupWindow; public void Controls() { + if (_menuPopupWindow == null) + { + _menuPopupWindow = new MenuPopupWindow(); + graphEditor.AddContextMenuItems(_menuPopupWindow); + } wantsMouseMove = true; Event e = Event.current; switch (e.type) { @@ -219,12 +225,9 @@ namespace XNodeEditor { } // Open context menu for auto-connection else if (NodeEditorPreferences.GetSettings().dragToCreate && autoConnectOutput != null) { - MenuPopupWindow menu = new MenuPopupWindow(); - graphEditor.AddContextMenuItems(menu); + _menuPopupWindow.OnCloseA = _releaseDraggedConnection; - menu.OnCloseA += _releaseDraggedConnection; - - PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero),menu); + PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero),_menuPopupWindow); } _releaseDraggedConnection(); @@ -281,10 +284,8 @@ namespace XNodeEditor { menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); e.Use(); // Fixes copy/paste context menu appearing in Unity 5.6.6f2 - doesn't occur in 2018.3.2f1 Probably needs to be used in other places. } else if (!IsHoveringNode) { - autoConnectOutput = null; - MenuPopupWindow menu = new MenuPopupWindow(); - graphEditor.AddContextMenuItems(menu); - PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero),menu); + autoConnectOutput = null; + PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero),_menuPopupWindow); } } isPanning = false; diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index 8c8f8bb..a1b222d 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -106,7 +106,6 @@ namespace XNodeEditor { void OnFocus() { current = this; ValidateGraphEditor(); - graphEditor?.OnFocus(); if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); }