forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUISkin.cs
More file actions
359 lines (287 loc) · 15 KB
/
GUISkin.cs
File metadata and controls
359 lines (287 loc) · 15 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Scripting;
namespace UnityEngine
{
// Which platform to emulate.
internal enum PlatformSelection
{
// The behaviour matches the platform the end user is running on.
Native = 0,
// The behaviour matches a Mac OS X machine.
Mac = 1,
// The behaviour matches a Windows machine.
Windows = 2,
}
// General settings for how the GUI behaves
[Serializable]
public sealed partial class GUISettings
{
// Should double-clicking select words in text fields.
public bool doubleClickSelectsWord { get { return m_DoubleClickSelectsWord; } set { m_DoubleClickSelectsWord = value; } }
[SerializeField]
bool m_DoubleClickSelectsWord = true;
// Should triple-clicking select whole text in text fields.
public bool tripleClickSelectsLine { get { return m_TripleClickSelectsLine; } set { m_TripleClickSelectsLine = value; } }
[SerializeField]
bool m_TripleClickSelectsLine = true;
// The color of the cursor in text fields.
public Color cursorColor { get { return m_CursorColor; } set { m_CursorColor = value; } }
[SerializeField]
Color m_CursorColor = Color.white;
// The speed of text field cursor flashes.
public float cursorFlashSpeed
{
get
{
if (m_CursorFlashSpeed >= 0)
return m_CursorFlashSpeed;
else
{
return Internal_GetCursorFlashSpeed();
}
}
set { m_CursorFlashSpeed = value; }
}
[SerializeField]
float m_CursorFlashSpeed = -1;
// The color of the selection rect in text fields.
public Color selectionColor { get { return m_SelectionColor; } set { m_SelectionColor = value; } }
[SerializeField]
Color m_SelectionColor = new Color(.5f, .5f, 1f);
}
// Defines how GUI looks and behaves.
[Serializable]
[ExecuteInEditMode]
[RequiredByNativeCode]
[AssetFileNameExtension("guiskin")]
public sealed class GUISkin : ScriptableObject
{
[SerializeField]
Font m_Font;
// *undocumented*
public GUISkin()
{
m_CustomStyles = new GUIStyle[1];
}
internal void OnEnable()
{
Apply();
}
static internal void CleanupRoots()
{
// See GUI.CleanupRoots
current = null;
ms_Error = null;
}
// The default font to use for all styles.
public Font font { get { return m_Font; } set { m_Font = value; if (current == this) GUIStyle.SetDefaultFont(m_Font); Apply(); } }
[SerializeField] //yes the attribute applies to all fields on the line below.
GUIStyle m_box, m_button, m_toggle, m_label, m_textField, m_textArea, m_window;
// Style used by default for GUI::ref::Box controls.
public GUIStyle box { get { return m_box; } set { m_box = value; Apply(); } }
// Style used by default for GUI::ref::Label controls.
public GUIStyle label { get { return m_label; } set { m_label = value; Apply(); } }
// Style used by default for GUI::ref::TextField controls.
public GUIStyle textField { get { return m_textField; } set { m_textField = value; Apply(); } }
// Style used by default for GUI::ref::TextArea controls.
public GUIStyle textArea { get { return m_textArea; } set { m_textArea = value; Apply(); } }
// Style used by default for GUI::ref::Button controls.
public GUIStyle button { get { return m_button; } set { m_button = value; Apply(); } }
// Style used by default for GUI::ref::Toggle controls.
public GUIStyle toggle { get { return m_toggle; } set { m_toggle = value; Apply(); } }
// Style used by default for Window controls (SA GUI::ref::Window).
public GUIStyle window { get { return m_window; } set { m_window = value; Apply(); } }
[SerializeField]
GUIStyle m_horizontalSlider;
[SerializeField]
GUIStyle m_horizontalSliderThumb;
[SerializeField]
GUIStyle m_verticalSlider;
[SerializeField]
GUIStyle m_verticalSliderThumb;
// Style used by default for the background part of GUI::ref::HorizontalSlider controls.
public GUIStyle horizontalSlider { get { return m_horizontalSlider; } set { m_horizontalSlider = value; Apply(); } }
// Style used by default for the thumb that is dragged in GUI::ref::HorizontalSlider controls.
public GUIStyle horizontalSliderThumb { get { return m_horizontalSliderThumb; } set { m_horizontalSliderThumb = value; Apply(); } }
// Style used by default for the background part of GUI::ref::VerticalSlider controls.
public GUIStyle verticalSlider { get { return m_verticalSlider; } set { m_verticalSlider = value; Apply(); } }
// Style used by default for the thumb that is dragged in GUI::ref::VerticalSlider controls.
public GUIStyle verticalSliderThumb { get { return m_verticalSliderThumb; } set { m_verticalSliderThumb = value; Apply(); } }
[SerializeField]
GUIStyle m_horizontalScrollbar;
[SerializeField]
GUIStyle m_horizontalScrollbarThumb;
[SerializeField]
GUIStyle m_horizontalScrollbarLeftButton;
[SerializeField]
GUIStyle m_horizontalScrollbarRightButton;
// Style used by default for the background part of GUI::ref::HorizontalScrollbar controls.
public GUIStyle horizontalScrollbar { get { return m_horizontalScrollbar; } set { m_horizontalScrollbar = value; Apply(); } }
// Style used by default for the thumb that is dragged in GUI::ref::HorizontalScrollbar controls.
public GUIStyle horizontalScrollbarThumb { get { return m_horizontalScrollbarThumb; } set { m_horizontalScrollbarThumb = value; Apply(); } }
// Style used by default for the left button on GUI::ref::HorizontalScrollbar controls.
public GUIStyle horizontalScrollbarLeftButton { get { return m_horizontalScrollbarLeftButton; } set { m_horizontalScrollbarLeftButton = value; Apply(); } }
// Style used by default for the right button on GUI::ref::HorizontalScrollbar controls.
public GUIStyle horizontalScrollbarRightButton { get { return m_horizontalScrollbarRightButton; } set { m_horizontalScrollbarRightButton = value; Apply(); } }
[SerializeField]
GUIStyle m_verticalScrollbar;
[SerializeField]
GUIStyle m_verticalScrollbarThumb;
[SerializeField]
GUIStyle m_verticalScrollbarUpButton;
[SerializeField]
GUIStyle m_verticalScrollbarDownButton;
// Style used by default for the background part of GUI::ref::VerticalScrollbar controls.
public GUIStyle verticalScrollbar { get { return m_verticalScrollbar; } set { m_verticalScrollbar = value; Apply(); } }
// Style used by default for the thumb that is dragged in GUI::ref::VerticalScrollbar controls.
public GUIStyle verticalScrollbarThumb { get { return m_verticalScrollbarThumb; } set { m_verticalScrollbarThumb = value; Apply(); } }
// Style used by default for the up button on GUI::ref::VerticalScrollbar controls.
public GUIStyle verticalScrollbarUpButton { get { return m_verticalScrollbarUpButton; } set { m_verticalScrollbarUpButton = value; Apply(); } }
// Style used by default for the down button on GUI::ref::VerticalScrollbar controls.
public GUIStyle verticalScrollbarDownButton { get { return m_verticalScrollbarDownButton; } set { m_verticalScrollbarDownButton = value; Apply(); } }
// Background style for scroll views.
[SerializeField]
GUIStyle m_ScrollView;
// Style used by default for the background of ScrollView controls (see GUI::ref::BeginScrollView).
public GUIStyle scrollView { get { return m_ScrollView; } set { m_ScrollView = value; Apply(); } }
[SerializeField]
internal GUIStyle[] m_CustomStyles;
// Array of GUI styles for specific needs.
public GUIStyle[] customStyles { get { return m_CustomStyles; } set { m_CustomStyles = value; Apply(); } }
[SerializeField]
private GUISettings m_Settings = new GUISettings();
// Generic settings for how controls should behave with this skin.
public GUISettings settings { get { return m_Settings; } }
internal static GUIStyle ms_Error;
internal static GUIStyle error { get { if (ms_Error == null) ms_Error = new GUIStyle(); return ms_Error; } }
private Dictionary<string, GUIStyle> m_Styles = null;
internal void Apply()
{
if (m_CustomStyles == null)
Debug.Log("custom styles is null");
BuildStyleCache();
}
private void BuildStyleCache()
{
if (m_box == null) m_box = new GUIStyle();
if (m_button == null) m_button = new GUIStyle();
if (m_toggle == null) m_toggle = new GUIStyle();
if (m_label == null) m_label = new GUIStyle();
if (m_window == null) m_window = new GUIStyle();
if (m_textField == null) m_textField = new GUIStyle();
if (m_textArea == null) m_textArea = new GUIStyle();
if (m_horizontalSlider == null) m_horizontalSlider = new GUIStyle();
if (m_horizontalSliderThumb == null) m_horizontalSliderThumb = new GUIStyle();
if (m_verticalSlider == null) m_verticalSlider = new GUIStyle();
if (m_verticalSliderThumb == null) m_verticalSliderThumb = new GUIStyle();
if (m_horizontalScrollbar == null) m_horizontalScrollbar = new GUIStyle();
if (m_horizontalScrollbarThumb == null) m_horizontalScrollbarThumb = new GUIStyle();
if (m_horizontalScrollbarLeftButton == null) m_horizontalScrollbarLeftButton = new GUIStyle();
if (m_horizontalScrollbarRightButton == null) m_horizontalScrollbarRightButton = new GUIStyle();
if (m_verticalScrollbar == null) m_verticalScrollbar = new GUIStyle();
if (m_verticalScrollbarThumb == null) m_verticalScrollbarThumb = new GUIStyle();
if (m_verticalScrollbarUpButton == null) m_verticalScrollbarUpButton = new GUIStyle();
if (m_verticalScrollbarDownButton == null) m_verticalScrollbarDownButton = new GUIStyle();
if (m_ScrollView == null) m_ScrollView = new GUIStyle();
m_Styles = new Dictionary<string, GUIStyle>(StringComparer.OrdinalIgnoreCase);
m_Styles["box"] = m_box;
m_box.name = "box";
m_Styles["button"] = m_button;
m_button.name = "button";
m_Styles["toggle"] = m_toggle;
m_toggle.name = "toggle";
m_Styles["label"] = m_label;
m_label.name = "label";
m_Styles["window"] = m_window;
m_window.name = "window";
m_Styles["textfield"] = m_textField;
m_textField.name = "textfield";
m_Styles["textarea"] = m_textArea;
m_textArea.name = "textarea";
m_Styles["horizontalslider"] = m_horizontalSlider;
m_horizontalSlider.name = "horizontalslider";
m_Styles["horizontalsliderthumb"] = m_horizontalSliderThumb;
m_horizontalSliderThumb.name = "horizontalsliderthumb";
m_Styles["verticalslider"] = m_verticalSlider;
m_verticalSlider.name = "verticalslider";
m_Styles["verticalsliderthumb"] = m_verticalSliderThumb;
m_verticalSliderThumb.name = "verticalsliderthumb";
m_Styles["horizontalscrollbar"] = m_horizontalScrollbar;
m_horizontalScrollbar.name = "horizontalscrollbar";
m_Styles["horizontalscrollbarthumb"] = m_horizontalScrollbarThumb;
m_horizontalScrollbarThumb.name = "horizontalscrollbarthumb";
m_Styles["horizontalscrollbarleftbutton"] = m_horizontalScrollbarLeftButton;
m_horizontalScrollbarLeftButton.name = "horizontalscrollbarleftbutton";
m_Styles["horizontalscrollbarrightbutton"] = m_horizontalScrollbarRightButton;
m_horizontalScrollbarRightButton.name = "horizontalscrollbarrightbutton";
m_Styles["verticalscrollbar"] = m_verticalScrollbar;
m_verticalScrollbar.name = "verticalscrollbar";
m_Styles["verticalscrollbarthumb"] = m_verticalScrollbarThumb;
m_verticalScrollbarThumb.name = "verticalscrollbarthumb";
m_Styles["verticalscrollbarupbutton"] = m_verticalScrollbarUpButton;
m_verticalScrollbarUpButton.name = "verticalscrollbarupbutton";
m_Styles["verticalscrollbardownbutton"] = m_verticalScrollbarDownButton;
m_verticalScrollbarDownButton.name = "verticalscrollbardownbutton";
m_Styles["scrollview"] = m_ScrollView;
m_ScrollView.name = "scrollview";
if (m_CustomStyles != null)
{
for (int i = 0; i < m_CustomStyles.Length; i++)
{
if (m_CustomStyles[i] == null)
continue;
m_Styles[m_CustomStyles[i].name] = m_CustomStyles[i];
}
}
error.stretchHeight = true;
error.normal.textColor = Color.red;
}
// Get a named [[GUIStyle]].
public GUIStyle GetStyle(string styleName)
{
GUIStyle s = FindStyle(styleName);
if (s != null)
return s;
Debug.LogWarning("Unable to find style '" + styleName + "' in skin '" + name + "' " + Event.current.type);
return error;
}
// Try to search for a [[GUIStyle]]. This functions returns NULL and does not give an error.
public GUIStyle FindStyle(string styleName)
{
if (this == null)
{
Debug.LogError("GUISkin is NULL");
return null;
}
if (m_Styles == null)
BuildStyleCache();
GUIStyle style;
if (m_Styles.TryGetValue(styleName, out style))
return style;
return null;
}
internal delegate void SkinChangedDelegate();
internal static SkinChangedDelegate m_SkinChanged;
// Make this the current skin used by the GUI
static internal GUISkin current;
internal void MakeCurrent()
{
current = this;
GUIStyle.SetDefaultFont(font);
if (m_SkinChanged != null)
m_SkinChanged();
}
//*undocumented* Documented separately
public IEnumerator GetEnumerator()
{
if (m_Styles == null)
BuildStyleCache();
return m_Styles.Values.GetEnumerator();
}
}
}