public static void ShowAsPopup(Rect buttonPosition, TreeItem[] rootItems, TreeItem selectedItem, string search = "", SearchChangedEventHandler onSearchChanged = null)
        {
            SearchablePopup searchable = new SearchablePopup();

            searchable.m_Items        = new List <TreeItem>(rootItems);
            searchable.m_SelectedItem = selectedItem;
            searchable.m_SearchString = search;
            if (onSearchChanged != null)
            {
                searchable.SearchChanged += onSearchChanged;
            }
            searchable.ApplyFilter();


            if (Event.current != null)
            {
                // If the event is not null, then we're inside OnGUI so can use the default Unity popup
                SearchablePopupContent content = new SearchablePopupContent(buttonPosition, searchable);
                searchable.SetEditorWindow(() => content.editorWindow);
                PopupWindow.Show(buttonPosition, content);
            }
            else
            {
                // Otherwise, the OnGUI version will throw an exception so use our own Editor window
                SearchablePopupEditorWindow.ShowAsPopup(buttonPosition, searchable);
            }
        }
Example #2
0
        public static void ShowAsPopup(Rect buttonRect, SearchablePopup content)
        {
            SearchablePopupEditorWindow window = CreateInstance <SearchablePopupEditorWindow>();

            window.Init(buttonRect, content);
        }