-
Notifications
You must be signed in to change notification settings - Fork 0
/
StyleExplorer.cs
147 lines (125 loc) · 5.38 KB
/
StyleExplorer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
public static class StringExtensions
{
public static bool Contains(this string source, string toCheck, StringComparison comp)
{
return source?.IndexOf(toCheck, comp) >= 0;
}
}
public class StyleExplorer : EditorWindow
{
private Vector2 rightScroll;
private Vector2 leftScroll;
private int styles;
private string query = "";
private int selection;
private List<string> styleNames = new List<string>();
private List<GUIStyle> foundStyles = new List<GUIStyle>();
private GUIStyle style = new GUIStyle();
private List<GUIStyle> customStyles = new List<GUIStyle>();
private Rect textFieldRect;
private string textToShow = "Civelek Babacık";
private bool showSearchField = true;
private float searchFieldWidth = 0f;
private float curSearchFieldWidth = 0f;
[MenuItem("Window/StyleExplorer")]
static void Init()
{
StyleExplorer window = (StyleExplorer)GetWindow(typeof(StyleExplorer));
window.Show();
}
void Awake()
{
customStyles = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene).customStyles.ToList();
foundStyles = new List<GUIStyle>(customStyles);
styleNames = foundStyles.Select(x => x.name + " (" + customStyles.IndexOf(x) + ")").ToList();
}
void OnGUI()
{
GUISkin skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
GUILayout.BeginHorizontal();
leftScroll = GUILayout.BeginScrollView(leftScroll,GUILayout.Width(510f));
GUILayout.BeginVertical(GUILayout.Width(480f));
GUILayout.BeginHorizontal();
GUIStyle iconStyle = customStyles[251];
if(GUILayout.Button(EditorGUIUtility.IconContent("Search Icon"), customStyles[355], GUILayout.Height(50f), GUILayout.Width(50f)))
{
searchFieldWidth = showSearchField ? 425f : 0f;
showSearchField = showSearchField ? false : true;
}
GUIStyle fieldStyle = customStyles[407];
fieldStyle.alignment = TextAnchor.MiddleLeft;
fieldStyle.fontSize = GUI.skin.font.fontSize + 5;
curSearchFieldWidth = Mathf.Lerp(curSearchFieldWidth, searchFieldWidth, 0.1f);
GUI.SetNextControlName("SearchBar");
query = GUILayout.TextField(query, fieldStyle, GUILayout.Height(50f),GUILayout.Width(curSearchFieldWidth));
textFieldRect = GUILayoutUtility.GetLastRect();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Text to show :", GUILayout.Width(100f));
textToShow = GUILayout.TextField(textToShow);
GUILayout.EndHorizontal();
GUILayout.Label("Style Name : " + style.name + " (" + customStyles.IndexOf(style) + ")", EditorStyles.boldLabel);
if(GUI.GetNameOfFocusedControl() == "SearchBar")
{
foundStyles = customStyles.FindAll(x => (x.name + " (" + customStyles.IndexOf(x) + ")").Contains(query, StringComparison.OrdinalIgnoreCase));
styleNames = foundStyles.Select(x => x.name + " (" + customStyles.IndexOf(x) + ")").ToList();
}
selection = GUILayout.SelectionGrid(selection, styleNames.ToArray(), 1);
if (foundStyles.Count>0)
{
if (selection > foundStyles.Count - 1)
selection = 0;
style = foundStyles[selection];
}
if (Event.current.keyCode == KeyCode.Return || (Event.current.type == EventType.MouseDown && !textFieldRect.Contains(Event.current.mousePosition)))
{
GUI.FocusControl(null);
Repaint();
}
if (Event.current.type == EventType.KeyDown)
{
if (Event.current.keyCode == KeyCode.DownArrow)
{
selection++;
if (selection > foundStyles.Count - 1)
selection = foundStyles.Count - 1;
leftScroll.y = selection * 21f - 300f;
Event.current.Use();
}
if (Event.current.keyCode == KeyCode.UpArrow)
{
selection--;
if (selection < 0)
selection = 0;
leftScroll.y = selection * 21f - 300f;
Event.current.Use();
}
}
//foreach(GUIStyle curStyle in foundStyles)
//{
//}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.BeginVertical();
//32,33,58,425 ez shadow,457
rightScroll = GUILayout.BeginScrollView(rightScroll);
GUILayout.Button(textToShow + "\n" + textToShow + "\n" + textToShow, style);
GUILayout.Label(textToShow, style);
GUILayout.Toolbar(0, new[] { textToShow, textToShow }, style);
GUILayout.Box(textToShow + "\n" + textToShow + "\n" + textToShow + "\n" + textToShow, style);
GUILayout.Box(textToShow, style, GUILayout.Width(100), GUILayout.Height(100));
GUILayout.Box(textToShow, style, GUILayout.Width(250), GUILayout.Height(300));
GUILayout.Toggle(true, textToShow);
GUILayout.Toggle(false, textToShow);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
Repaint();
}
}