From 07217505e67dccdd0cb91ad3b8cca5116460b362 Mon Sep 17 00:00:00 2001 From: Icarus <1375400884@qq.com> Date: Tue, 26 Nov 2019 17:42:30 +0800 Subject: [PATCH] =?UTF-8?q?!W=20=E6=90=9C=E7=B4=A2=E6=97=B6=E6=8C=89?= =?UTF-8?q?=E4=B8=8B`=E2=86=93`=E9=94=AE=E5=88=87=E6=8D=A2=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E5=88=B0`TreeView`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/Editor/NodeGraphEditor.cs | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index a17c1c4..2dc444b 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -10,6 +10,7 @@ namespace XNodeEditor { { private SearchField _search; private MenuTreeView _menuTree; + public Action OnCloseA; public MenuPopupWindow() { _search = new SearchField(); @@ -41,6 +42,11 @@ namespace XNodeEditor { _search.SetFocus(); } + public override void OnClose() + { + OnCloseA?.Invoke(); + } + private string _str; public override void OnGUI(Rect rect) { @@ -49,6 +55,8 @@ namespace XNodeEditor { Init(); } + _action(); + EditorGUI.BeginChangeCheck(); { _str = _search.OnGUI(new Rect(rect.position, new Vector2(rect.width, 20)),_str); @@ -60,6 +68,22 @@ namespace XNodeEditor { _menuTree.OnGUI(new Rect(new Vector2(0,25),rect.size - new Vector2(0,20))); } + + private void _action() + { + Event e = Event.current; + switch (e.type) + { + case EventType.KeyDown: + + if (e.keyCode == KeyCode.DownArrow && !_menuTree.HasFocus()) + { + _menuTree.SetFocusAndEnsureSelectedItem(); + e.Use(); + } + break; + } + } } public class MenuTreeView:TreeView { @@ -193,6 +217,38 @@ namespace XNodeEditor { { return Root; } + + protected override void KeyEvent() + { + Event e = Event.current; + switch (e.type) + { + case EventType.KeyDown: + + if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter) + { + DoubleClickedItem(GetSelection()[0]); + e.Use(); + } + break; + } + } + + private void _action() + { + Event e = Event.current; + switch (e.type) + { + case EventType.KeyDown: + + if (e.keyCode == KeyCode.DownArrow && !HasFocus()) + { + this.SetFocusAndEnsureSelectedItem(); + e.Use(); + } + break; + } + } } /// Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor.