using UnityEngine; using UnityEditor; using System.Collections.Generic; namespace YKMoonEditor { public class IMGUIStyleViewer : EditorWindow { private Vector2 scrollVector2 = Vector2.zero; private string search = ""; private string toolbarStyle = "AnimClipToolbarButton"; private float[] columnWidth = { 300, 120, 300, 300 }; private string[] columnName = { "Name", "Size", "Label", "Toggle" }; private float columnSpace = 40; //private float styleWidth = 300; //private float styleHeight = 300; [MenuItem("Window/YKTools/GUIStyleViewer")] public static void InitWindow() { EditorWindow.GetWindow(typeof(IMGUIStyleViewer)); } void OnGUI() { GUILayout.BeginHorizontal("HelpBox"); search = EditorGUILayout.TextField("Search", search, "SearchTextField", GUILayout.MaxWidth(position.width / 2)); GUILayout.EndHorizontal(); //Columns GUILayout.BeginHorizontal("HelpBox"); for(int i = 0; i < columnName.Length; i++) { float width = columnWidth[i] + (i > 0 ? columnSpace : 0); GUILayout.Label(columnName[i], toolbarStyle, GUILayout.Width(width), GUILayout.Width(width)); } GUILayout.EndHorizontal(); //Styles scrollVector2 = GUILayout.BeginScrollView(scrollVector2); foreach(GUIStyle style in GUI.skin.customStyles) { if(style.name.ToLower().Contains(search.ToLower())) { DrawStyleItem(style); } } GUILayout.EndScrollView(); } void DrawStyleItem(GUIStyle style) { GUILayout.BeginHorizontal("box"); int index = 0; //Name EditorGUILayout.SelectableLabel(style.name, "AnimClipToolbarButton", GUILayout.Width(columnWidth[index] -columnSpace)); if(GUILayout.Button("Copy", GUILayout.Width(columnSpace))) { TextEditor textEditor = new TextEditor(); textEditor.text = style.name; textEditor.OnFocus(); textEditor.Copy(); } index++; //Size EditorGUILayout.SelectableLabel(string.Format("{0},{1}", style.fixedWidth, style.fixedHeight), "AnimClipToolbarButton", GUILayout.Width(columnWidth[index]+ columnSpace)); index++; GUILayout.Space(columnSpace); var options = YKMoon.ListPool.Get(); float w = style.fixedWidth == 0 ? columnWidth[index] : style.fixedWidth; options.Add(GUILayout.Width(w)); if(style.fixedHeight != 0) { options.Add(GUILayout.Height(style.fixedHeight)); } options.Add(GUILayout.MinWidth(columnWidth[index])); options.Add(GUILayout.MaxWidth(w)); //Label EditorGUILayout.SelectableLabel(style.name, style, options.ToArray()); GUILayout.Space(columnSpace); index++; //Toggle var value = EditorGUILayout.Toggle(style.name, GetToggleState(style.name), style, options.ToArray()); SetToggleState(style.name,value); //Toggle GUILayout.EndHorizontal(); YKMoon.ListPool.Release(options); } private Dictionary toggleTrigger = new Dictionary(); private bool GetToggleState(string name) { if (!toggleTrigger.ContainsKey(name)) { toggleTrigger.Add(name, false); } return toggleTrigger[name]; } private void SetToggleState(string name, bool state) { toggleTrigger[name] = state; } } }