protected virtual void ShowListView() { List <T> source; bool b = GetSource(out source); if (b) { CurrSelect = source.FirstOrDefault(e => e == CurrSelect); } listScrollView = GUILayout.BeginScrollView(listScrollView); foreach (var item in source) { GUILayout.BeginHorizontal(); GUILayout.Space(20); if (item == CurrSelect) { GUITool.Button(this.GetItemName(item).SetSize(16, true).SetColor(Color.white), new Color(0, 0, 0, 0.3f)); GUILayout.FlexibleSpace(); } else { if (GUITool.Button(this.GetItemName(item), Color.clear, TextAnchor.MiddleLeft)) { CurrSelect = item; } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }
public TreeViewItemState Show() { var treeViewItemState = new TreeViewItemState(); if (this.IsSelect) { GUILayout.BeginHorizontal(GUITreeView.selectBackgroundStyle); var labelButton = GUITool.LabelButton("", GUILayout.Width(this.Depth * 20)); var button = GUITool.LabelButton(this.Name); if (labelButton || button) { treeViewItemState.SelectOperation = TreeViewSelectOperation.Deselect; } GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(GUITreeView.deselectBackgroundStyle); bool button = GUITool.LabelButton("", GUILayout.Width(this.Depth * 20)); if (GUITool.LabelButton(this.Name) || button) { treeViewItemState.SelectOperation = TreeViewSelectOperation.Select; } GUILayout.EndHorizontal(); } return(treeViewItemState); }
private void OnGUI() { GUI.skin.label.richText = true; GUI.skin.button.richText = true; GUI.skin.box.richText = true; GUI.skin.textArea.richText = true; GUI.skin.textField.richText = true; GUI.skin.toggle.richText = true; GUI.skin.window.richText = true; if (AutoAdjustSize) { GUILayout.BeginVertical(GUITool.GetAreaGUIStyle(new Color(0.3f, 0.3f, 0.3f)), GUILayout.Width(10), GUILayout.Height(10)); DrawOnGUI(); GUILayout.EndVertical(); Rect lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.size.x > 5 && lastRect.size.y > 5) { this.maxSize = lastRect.size; this.minSize = lastRect.size; } } else { this.ScrollViewPosition = GUILayout.BeginScrollView(this.ScrollViewPosition, GUITool.GetAreaGUIStyle(new Color(0.3f, 0.3f, 0.3f))); DrawOnGUI(); GUILayout.EndScrollView(); } }
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); } } }
public TreeViewItemState Show() { var treeViewItemState = new TreeViewItemState(); if (IsSelect) { GUILayout.BeginHorizontal(GUITreeView.selectBackgroundStyle); } else { GUILayout.BeginHorizontal(GUITreeView.deselectBackgroundStyle); } if (this.IsOpen) { bool selectButton = GUITool.LabelButton("", GUILayout.Width(this.Depth * 20)); bool closeButton = GUITool.LabelButton("\u25BC" + (char)0x200a, GUILayout.Width(12)); selectButton = GUITool.LabelButton(this.Name) || selectButton; if (closeButton) { treeViewItemState.OpenOperation = TreeViewOpenOperation.Close; } if (selectButton || closeButton) { treeViewItemState.SelectOperation = IsSelect ? TreeViewSelectOperation.Deselect : TreeViewSelectOperation.Select; } } else { bool selectButton = GUITool.LabelButton("", GUILayout.Width(this.Depth * 20)); var openButton = GUITool.LabelButton("\u25BA" + (char)0x200a, GUILayout.Width(12)); selectButton = GUITool.LabelButton(this.Name) || selectButton; if (openButton) { treeViewItemState.OpenOperation = TreeViewOpenOperation.Open; } if (selectButton) { treeViewItemState.SelectOperation = IsSelect ? TreeViewSelectOperation.Deselect : TreeViewSelectOperation.Select; } } GUILayout.EndHorizontal(); return(treeViewItemState); }
private void OnGUI() { GUI.skin.label.richText = true; GUI.skin.button.richText = true; GUI.skin.box.richText = true; GUI.skin.textArea.richText = true; GUI.skin.textField.richText = true; GUI.skin.toggle.richText = true; GUI.skin.window.richText = true; //GUILayout.Label(PlatformType.GetName(this.Platform).SetSize(20).SetBold()); GUILayout.Label(PlatformType.GetName(this.Platform)); FieldInspectorTool.ShowObject(this); var type = this.GetType(); var fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (var fieldInfo in fieldInfos) { this.SaveCacheValue(fieldInfo); } if (GUITool.Button("生成", Color.green)) { bfProductName = PlayerSettings.productName; if (!string.IsNullOrEmpty(productName.Trim())) { PlayerSettings.productName = productName.Trim(); } try { this.Build(); } catch (Exception e) { Debug.LogException(e); PlayerSettings.productName = bfProductName; } } this.PlatformGUI(); }
public static IList ListEditor(string prefix, IList list, Type listType) { if (list == null) { list = ReflecTool.Instantiate(listType) as IList; } var argType = listType.IsArray ? listType.GetElementType() : listType.GetGenericArguments()[0]; //register foldout if (!registeredEditorFoldouts.ContainsKey(list)) { registeredEditorFoldouts[list] = false; } GUILayout.BeginVertical(); var foldout = registeredEditorFoldouts[list]; foldout = EditorGUILayout.Foldout(foldout, prefix); registeredEditorFoldouts[list] = foldout; if (!foldout) { GUILayout.EndVertical(); return(list); } if (list.Equals(null)) { GUILayout.Label("Null List"); GUILayout.EndVertical(); return(list); } GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); if (GUILayout.Button("Add Element")) { if (listType.IsArray) { list = ResizeArray((Array)list, list.Count + 1); registeredEditorFoldouts[list] = true; } else { object newElement = null; if (argType.IsValueType) { newElement = Activator.CreateInstance(argType); } if (!argType.IsInterface && !argType.IsAbstract && AssemblyTool.FindTypesInCurrentDomainWhereExtend(argType).Count == 1) { try { newElement = Activator.CreateInstance(argType); } catch (Exception) { } } list.Add(newElement); } GUI.FocusControl(""); } // EditorGUI.indentLevel++; for (var i = 0; i < list.Count; i++) { GUILayout.BeginVertical(GUITool.GetAreaGUIStyle(new Color(Color.grey.r, Color.grey.g, Color.grey.b, 0.3f))); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); ShowObject(list[i]); GUILayout.EndVertical(); // list[i] = GenericField("Element " + i, list[i], argType, null, null, false); if (GUILayout.Button("X", GUILayout.Width(18))) { if (listType.IsArray) { list = ResizeArray((Array)list, list.Count - 1); registeredEditorFoldouts[list] = true; } else { list.RemoveAt(i); } GUI.FocusControl(""); } GUILayout.EndHorizontal(); GUITool.Line(2); GUILayout.EndVertical(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); // EditorGUI.indentLevel--; Separator(); GUILayout.EndVertical(); return(list); }
/// <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(); } } }
private void OpenSelectWindow(FieldInfo fieldInfo, object instance, string[] imgFolderPaths) { List <Texture2D> texture2Ds = new List <Texture2D>(); List <Texture2D> texture2Dss = new List <Texture2D>(); List <Texture2D> texture2Dsss = new List <Texture2D>(); var findAssets = AssetDatabase.FindAssets("", imgFolderPaths); Dictionary <string, string> loaded = new Dictionary <string, string>(); Dictionary <Texture2D, string> loadedTextureName = new Dictionary <Texture2D, string>(); Dictionary <Texture2D, string> loadedTexturePath = new Dictionary <Texture2D, string>(); foreach (var asset in findAssets) { var guidToAssetPath = AssetDatabase.GUIDToAssetPath(asset); if (!loaded.ContainsKey(guidToAssetPath)) { var loadAssetAtPath = AssetDatabase.LoadAssetAtPath <Texture2D>(guidToAssetPath); var pathSplit = guidToAssetPath.Split('/'); var imgName = pathSplit[pathSplit.Length - 1]; loaded[guidToAssetPath] = imgName; if (loadAssetAtPath != null) { loadedTextureName[loadAssetAtPath] = imgName; loadedTexturePath[loadAssetAtPath] = guidToAssetPath; texture2Ds.Add(loadAssetAtPath); } } } var popCustomWindow = new PopCustomWindow(); popCustomWindow.DefaultSize = new Vector2(600, 400); popCustomWindow.DrawGUI = () => { texture2Dsss = searchBar2.Draw(texture2Ds, item => item.name); if (searchBar2.SearchContent.IsNOTNullOrEmpty()) { texture2Dss = texture2Dsss; } else { texture2Dss = texture2Ds; } string selectPath = null; int i = 0; while (i < texture2Dss.Count) { GUILayout.BeginHorizontal(); for (int lineCount = 0; lineCount < 5 && i < texture2Dss.Count; lineCount++) { bool select = false; var texture2D = texture2Dss[i]; GUILayout.BeginVertical(); select = GUILayout.Button(new GUIContent(texture2D), GUILayout.Width(100), GUILayout.Height(100)); GUITool.Button(loadedTextureName[texture2D], Color.clear, GUILayout.MaxWidth(100)); GUILayout.EndVertical(); i++; if (select) { selectPath = loadedTexturePath[texture2D]; } } GUILayout.EndHorizontal(); } if (selectPath.IsNOTNullOrEmpty()) { var assetDatabasePathToFieldValue = this.AssetDatabasePathToFieldValue(selectPath); // Debug.Log(assetDatabasePathToFieldValue); fieldInfo.SetValue(instance, this.AssetDatabasePathToFieldValue(selectPath)); popCustomWindow.CloseWindow(); } }; popCustomWindow.PopWindow(); }