public override void DrawItem(AdvancedDropdownItem item, bool selected, bool hasSearch) { var nsItem = item as NewScriptDropdownItem; if (nsItem == null) { base.DrawItem(item, selected, hasSearch); return; } GUILayout.Label("Name", EditorStyles.label); EditorGUI.FocusTextInControl("NewScriptName"); GUI.SetNextControlName("NewScriptName"); nsItem.m_ClassName = EditorGUILayout.TextField(nsItem.m_ClassName); EditorGUILayout.Space(); EditorGUILayout.EnumPopup("Language", NewScriptDropdownItem.Language.CSharp); EditorGUILayout.Space(); var canCreate = nsItem.CanCreate(); if (!canCreate && nsItem.m_ClassName != "") { GUILayout.Label(nsItem.GetError(), EditorStyles.helpBox); } GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(!canCreate)) { if (GUILayout.Button("Create and Add")) { nsItem.Create(AddComponentWindow.s_AddComponentWindow.m_GameObjects); } } EditorGUILayout.Space(); }
internal void SetParent(AdvancedDropdownItem item) { m_Parent = item; }
internal void AddChild(AdvancedDropdownItem item) { children.Add(item); }
private void DrawList(AdvancedDropdownItem item) { // Start of scroll view list item.m_Scroll = GUILayout.BeginScrollView(item.m_Scroll); EditorGUIUtility.SetIconSize(gui.iconSize); Rect selectedRect = new Rect(); for (var i = 0; i < item.children.Count; i++) { var child = item.children[i]; bool selected = i == item.m_SelectedItem; gui.DrawItem(child, selected, hasSearch); var r = GUILayoutUtility.GetLastRect(); if (selected) { selectedRect = r; } // Select the element the mouse cursor is over. // Only do it on mouse move - keyboard controls are allowed to overwrite this until the next time the mouse moves. if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) { //if (parent.selectedIndex != i && r.Contains(Event.current.mousePosition)) if (!selected && r.Contains(Event.current.mousePosition)) { item.m_SelectedItem = i; Event.current.Use(); } } if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { item.m_SelectedItem = i; if (m_CurrentlyRenderedTree.GetSelectedChild().children.Any()) { GoToChild(m_CurrentlyRenderedTree); } else { if (m_CurrentlyRenderedTree.GetSelectedChild().OnAction()) { CloseWindow(); GUIUtility.ExitGUI(); } } Event.current.Use(); } } EditorGUIUtility.SetIconSize(Vector2.zero); GUILayout.EndScrollView(); // Scroll to show selected if (m_ScrollToSelected && Event.current.type == EventType.Repaint) { m_ScrollToSelected = false; Rect scrollRect = GUILayoutUtility.GetLastRect(); if (selectedRect.yMax - scrollRect.height > item.m_Scroll.y) { item.m_Scroll.y = selectedRect.yMax - scrollRect.height; Repaint(); } if (selectedRect.y < item.m_Scroll.y) { item.m_Scroll.y = selectedRect.y; Repaint(); } } }
virtual protected AdvancedDropdownItem Search(string searchString) { if (string.IsNullOrEmpty(searchString)) { return(null); } // Support multiple search words separated by spaces. var searchWords = searchString.ToLower().Split(' '); // We keep two lists. Matches that matches the start of an item always get first priority. var matchesStart = new List <AdvancedDropdownItem>(); var matchesWithin = new List <AdvancedDropdownItem>(); foreach (var e in m_MainTree.GetSearchableElements()) { var name = e.name.ToLower().Replace(" ", ""); var didMatchAll = true; var didMatchStart = false; // See if we match ALL the seaarch words. for (var w = 0; w < searchWords.Length; w++) { var search = searchWords[w]; if (name.Contains(search)) { // If the start of the item matches the first search word, make a note of that. if (w == 0 && name.StartsWith(search)) { didMatchStart = true; } } else { // As soon as any word is not matched, we disregard this item. didMatchAll = false; break; } } // We always need to match all search words. // If we ALSO matched the start, this item gets priority. if (didMatchAll) { if (didMatchStart) { matchesStart.Add(e); } else { matchesWithin.Add(e); } } } matchesStart.Sort(); matchesWithin.Sort(); var searchTree = new AdvancedDropdownItem(kSearchHeader, -1); foreach (var element in matchesStart) { searchTree.AddChild(element); } foreach (var element in matchesWithin) { searchTree.AddChild(element); } return(searchTree); }
public void RebuildSearch(string search) { m_SearchTree = Search(search); }
public void ReloadData() { m_MainTree = FetchData(); }