private static void AddItem(SearcherItem root, SearcherItem item, string[] pathParts) { string itemFullPath = item.Name; string itemName = pathParts[pathParts.Length - 1]; string currentPath = string.Empty; SearcherItem currentSearchNode = root; for (int i = 1; i < pathParts.Length; ++i) { SearcherItem node = FindNodeByName(currentSearchNode.Children, pathParts[i]); if (node == null) { node = new SearcherItem(pathParts[i]); currentSearchNode.AddChild(node); } currentSearchNode = node; } // Set the user data to the final node, which is guaranteed to correspond to the item. currentSearchNode.UserData = item.UserData; currentSearchNode.Icon = item.Icon; }
public override void OnInspectorGUI() { var root = new SearcherItem("Root"); var children = new List <SearcherItem>(); for (var i = 0; i < 10; ++i) { children.Add(new SearcherItem("B-" + i)); } var child = new SearcherItem("Child", "", children); root.AddChild(child); { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Mouse Position"); if (EditorGUILayout.DropdownButton(new GUIContent("Button"), FocusType.Passive, GUI.skin.button)) { var editorWindow = EditorWindow.focusedWindow; var localMousePosition = Event.current.mousePosition; var worldMousePosition = editorWindow.rootVisualElement.LocalToWorld(localMousePosition); SearcherWindow.Show( editorWindow, new List <SearcherItem> { root }, "Mouse Position", item => { Debug.Log("Searcher item selected: " + (item?.Name ?? "<none>")); return(true); }, worldMousePosition); } EditorGUILayout.EndHorizontal(); } { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Button Center"); var selected = EditorGUILayout.DropdownButton(new GUIContent("Button"), FocusType.Passive, GUI.skin.button); if (Event.current.type == EventType.Repaint) { m_ButtonRect = GUILayoutUtility.GetLastRect(); } if (selected) { var editorWindow = EditorWindow.focusedWindow; var localButtonCenter = m_ButtonRect.center; var worldButtonCenter = editorWindow.rootVisualElement.LocalToWorld(localButtonCenter); SearcherWindow.Show( editorWindow, new List <SearcherItem> { root }, "Button Center", item => { Debug.Log("Searcher item selected: " + (item?.Name ?? "<none>")); return(true); }, worldButtonCenter); } EditorGUILayout.EndHorizontal(); } }