This repository was archived by the owner on Apr 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorSkinUtility.cs
More file actions
269 lines (241 loc) · 9.56 KB
/
EditorSkinUtility.cs
File metadata and controls
269 lines (241 loc) · 9.56 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Argos.Framework.Utils
{
/// <summary>
/// Help functions to manage Unity editor skin theme.
/// </summary>
public static class EditorSkinUtility
{
#region Structs
/// <summary>
/// Custom editor colors.
/// </summary>
public readonly struct Colors
{
#region Constants
public static readonly Color bright = EditorGUIUtility.isProSkin ? (Color)(new Color32(98, 98, 98, 255)) : new Color(0.4823529f, 0.4862745f, 0.4823529f, 1f);
public static readonly Color dark = new Color(0.9333333f, 0.9372549f, 0.9333333f, 1f);
#endregion
}
#endregion
#region Classes
class GUIStyleProperty
{
#region Internal vars
string _name;
GUIStyle _style;
Func<GUIStyle, GUIStyle> _customInitialization;
#endregion
#region Constructors
public GUIStyleProperty(string name, Func<GUIStyle, GUIStyle> customInitialization = null)
{
this._name = name;
this._customInitialization = customInitialization;
}
#endregion
#region Operators
public static implicit operator GUIStyle(GUIStyleProperty item)
{
if (item._style == null)
{
item._style = EditorSkinUtility.Skin.GetStyle(item._name).Copy();
if (item._customInitialization != null)
{
item._style = item._customInitialization(item._style);
}
}
return item._style;
}
#endregion
}
class GUIContentProperty
{
#region Internal vars
string _name;
GUIContent _content;
Func<GUIContent, GUIContent> _customInitialization;
#endregion
#region Constructors
public GUIContentProperty(string name, Func<GUIContent, GUIContent> customInitialization = null)
{
this._name = name;
this._customInitialization = customInitialization;
}
#endregion
#region Operators
public static implicit operator GUIContent(GUIContentProperty item) => item.GetContent();
public static implicit operator Texture(GUIContentProperty item) => item.GetContent().image;
public static implicit operator string(GUIContentProperty item) => item.GetContent().text;
#endregion
GUIContent GetContent()
{
if (this._content == null)
{
this._content = EditorGUIUtility.IconContent(this._name).Copy();
if (this._customInitialization != null)
{
this._content = this._customInitialization(this._content);
}
}
return this._content;
}
}
/// <summary>
/// Editor styles.
/// </summary>
/// <remarks>This class exposed some cached built-in skin editor styles and Argos.Framework custom style variations.</remarks>
public static class Styles
{
#region Constants
/// <summary>
/// Unity built-in "box" style.
/// </summary>
public readonly static GUIStyle box = new GUIStyleProperty("box");
/// <summary>
/// Unity built-in "window" style.
/// </summary>
public readonly static GUIStyle window = new GUIStyleProperty("window");
#endregion
#region Classes
/// <summary>
/// Unity built-in custom styles.
/// </summary>
public static class Custom
{
#region Constants
/// <summary>
/// "grey_border" custom style.
/// </summary>
public readonly static GUIStyle greyBorder = new GUIStyleProperty("grey_border");
/// <summary>
/// "InvisibleButton" custom style.
/// </summary>
public readonly static GUIStyle invisibleButton = new GUIStyleProperty("invisibleButton");
/// <summary>
/// "FrameBox" custom style (like the "Helpbox" style).
/// </summary>
public readonly static GUIStyle frameBox = new GUIStyleProperty("FrameBox");
#endregion
#region Classes
/// <summary>
/// ReorderableList styles.
/// </summary>
public static class ReorderableList
{
#region Constants
/// <summary>
/// "RL DragHandle" custom style.
/// </summary>
public readonly static GUIStyle dragHandle = new GUIStyleProperty("RL DragHandle");
#endregion
}
/// <summary>
/// Toolbar Search styles.
/// </summary>
public static class ToolbarSearch
{
#region Constants
/// <summary>
/// "ToolbarSearchField" custom style.
/// </summary>
public readonly static GUIStyle textField = new GUIStyleProperty("ToolbarSeachTextField");
/// <summary>
/// "ToolbarSeachTextFieldPopup" custom style.
/// </summary>
public readonly static GUIStyle textFieldPopup = new GUIStyleProperty("ToolbarSeachTextFieldPopup");
/// <summary>
/// "ToolbarSeachCancelButton" custom style.
/// </summary>
public readonly static GUIStyle cancelButton = new GUIStyleProperty("ToolbarSeachCancelButton");
/// <summary>
/// "ToolbarSeachCancelButtonEmpty" custom style.
/// </summary>
public readonly static GUIStyle cancelButtonEmpty = new GUIStyleProperty("ToolbarSeachCancelButtonEmpty");
#endregion
}
#endregion
}
/// <summary>
/// Argos.Framework custom styles based or derived from Unity built-in styles.
/// </summary>
public static class ArgosCustomVariants
{
#region Constants
/// <summary>
/// Fixed version of built-in label style to fix text aligment in Unity 2019.3 or newer versions.
/// </summary>
public readonly static GUIStyle upperLeftAligmentLabel = new GUIStyleProperty("label", (style) =>
{
style.alignment = TextAnchor.UpperLeft;
return style;
});
/// <summary>
/// "invisibleButton" custom style with transparent color on normal.textColor property.
/// </summary>
public readonly static GUIStyle invisibleButtonWithTransparentText = new GUIStyleProperty("invisibleButton", (style) =>
{
style.normal.textColor = Color.clear;
return style;
});
/// <summary>
/// "miniLabel" custom style with disable color on normal.textColor property.
/// </summary>
public readonly static GUIStyle disabledMiniLabel = new GUIStyleProperty("miniLabel", (style) =>
{
Color color = style.normal.textColor;
color.a = 0.5f;
style.normal.textColor = color;
return style;
});
/// <summary>
/// "miniLabel" custom style with red color on normal.textColor property.
/// </summary>
public readonly static GUIStyle errorMiniLabel = new GUIStyleProperty("miniLabel", (style) =>
{
style.normal.textColor = Color.red;
return style;
});
#endregion
}
#endregion
}
/// <summary>
/// Unity built-in icons.
/// </summary>
/// <remarks>This class exposed some cached built-in editor icons.</remarks>
public static class Icons
{
#region Classes
/// <summary>
/// Debug console icons.
/// </summary>
public static class Console
{
#region Constants
/// <summary>
/// "console.erroricon.sml" icon.
/// </summary>
public readonly static GUIContent errorIcon = new GUIContentProperty("console.erroricon.sml");
#endregion
}
#endregion
}
#endregion
#region Properties
/// <summary>
/// Returns the current Unity editor skin.
/// </summary>
public static GUISkin Skin
{
get
{
return EditorGUIUtility.GetBuiltinSkin(EditorGUIUtility.isProSkin ? EditorSkin.Scene : EditorSkin.Inspector);
}
}
#endregion
}
}