protected override void DrawOnGUI() { if (this.Name.IsNOTNullOrEmpty()) { GUILayout.BeginHorizontal("flow overlay box"); GUITool.Button(this.Name, Color.clear); GUILayout.EndHorizontal(); } var items = this.selectItems; if (this.HasSearchBar) { if (this.searchBar == null) { this.searchBar = new GUISearchBar <SelectItem>(); } items = this.searchBar.Draw(this.selectItems, item => item.Name); } for (int i = 0; i < items.Count; i++) { bool toggle = EditorGUILayout.Toggle(items[i].Name, items[i].On); if (toggle != items[i].On) { items[i].On = toggle; this.OnSelectChange(items[i].Name, items[i].On); } } }
/// <summary> /// The draw on gui. /// </summary> protected override void DrawOnGUI() { if (this.Items.Count == 0) { return; } var levelName = this.menuNameStack[this.menuNameStack.Count - 1]; var levelPath = this.menuNameStack.Joint("/"); List <PopMenuWindowItem> items = this.Items[levelPath]; if (this.HasSearchBar) { if (this.searchBar == null) { this.searchBar = new GUISearchBar <PopMenuWindowItem>(); } var searchItems = this.searchBar.Draw(this.ItemList, item => item.GetItemName()); if (this.searchBar.SearchContent.IsNOTNullOrEmpty()) { items = searchItems; if (this.MenuName.IsNOTNullOrEmpty()) { levelName = SearchLevelName; } } } if (levelName.IsNOTNullOrEmpty()) { GUILayout.BeginHorizontal(GUITool.GetAreaGUIStyle(new Color(0, 0, 0, 0.2f))); if (this.menuNameStack.Count >= 2 && levelName != SearchLevelName) { if (GUITool.Button("◀", Color.clear, GUILayout.Width(30)) || GUITool.Button(levelName, Color.clear) || GUITool.Button(" ", Color.clear, GUILayout.Width(30))) { this.menuNameStack.RemoveAt(this.menuNameStack.Count - 1); } } else { GUITool.Button(levelName, Color.clear); } GUILayout.EndHorizontal(); } if (!this.AutoAdjustSize) { this.scroll = GUILayout.BeginScrollView(this.scroll); } if (this.AutoSortItem) { items.Sort( (l, r) => { if (l is PopMenuWindowItemJump) { return(1); } if (r is PopMenuWindowItemJump) { return(-1); } return(StringComparer.CurrentCulture.Compare(l.GetItemName(), r.GetItemName())); }); } foreach (var popMenuWindowItem in items) { if (popMenuWindowItem.Show()) { popMenuWindowItem.Select(); } } if (!this.AutoAdjustSize) { GUILayout.EndScrollView(); } if (Event.current.type == EventType.KeyUp && !Event.current.alt && !Event.current.command && Event.current.shift && !Event.current.control) { if (this.searchBar == null || string.IsNullOrEmpty(this.searchBar.SearchContent)) { if (Event.current.keyCode == KeyCode.Backspace) { } else if (Event.current.keyCode == KeyCode.Escape) { if (this.menuNameStack.Count >= 2 && levelName != SearchLevelName) { this.menuNameStack.RemoveAt(this.menuNameStack.Count - 1); Event.current.Use(); } } else { foreach (var menuWindowItem in items) { if (menuWindowItem.ShortcutKey == Event.current.keyCode) { menuWindowItem.Select(); Event.current.Use(); break; } } // var popMenuWindowItem = items[UnityEngine.Random.Range(0, items.Count - 1)]; // popMenuWindowItem.Select(); } // this.PageTo(); } } }