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
|
C++RAW
#include "UnityPrefix.h"
#include "Runtime/Misc/InputEvent.h"
#include "Runtime/Scripting/ScriptingUtility.h"
CSRAW
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
namespace UnityEngine
{
// Which platform to emulate.
ENUM internal 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,
END
// General settings for how the GUI behaves
CSRAW [System.Serializable]
CLASS GUISettings
// Should double-clicking select words in text fields.
CSRAW public bool doubleClickSelectsWord { get { return m_DoubleClickSelectsWord; } set { m_DoubleClickSelectsWord = value; } }
CSRAW [SerializeField]
CSRAW bool m_DoubleClickSelectsWord = true;
// Should triple-clicking select whole text in text fields.
CSRAW public bool tripleClickSelectsLine { get { return m_TripleClickSelectsLine; } set { m_TripleClickSelectsLine = value; } }
CSRAW [SerializeField]
CSRAW bool m_TripleClickSelectsLine = true;
// The color of the cursor in text fields.
CSRAW public Color cursorColor { get { return m_CursorColor; } set { m_CursorColor = value; } }
CSRAW [SerializeField]
CSRAW Color m_CursorColor = Color.white;
CUSTOM private static float Internal_GetCursorFlashSpeed () {
#if UNITY_OSX && !UNITY_64
return 60.0f / GetCaretTime();
#elif UNITY_WIN && !UNITY_WINRT
return 1000.0f / GetCaretBlinkTime();
#elif UNITY_WII || UNITY_XENON || UNITY_PS3 || UNITY_IPHONE || UNITY_ANDROID || UNITY_PEPPER || UNITY_LINUX || UNITY_FLASH || UNITY_WEBGL || UNITY_WINRT || UNITY_OSX || UNITY_BB10 || UNITY_TIZEN
return 2.0f;
#else
#error "Unknown platform"
#endif
}
// The speed of text field cursor flashes.
CSRAW public float cursorFlashSpeed { get {
if (m_CursorFlashSpeed >= 0)
return m_CursorFlashSpeed;
else {
return Internal_GetCursorFlashSpeed ();
}
}
set { m_CursorFlashSpeed = value; } }
CSRAW [SerializeField]
CSRAW float m_CursorFlashSpeed = -1;
// The color of the selection rect in text fields.
CSRAW public Color selectionColor { get { return m_SelectionColor; } set { m_SelectionColor = value; } }
CSRAW [SerializeField]
CSRAW Color m_SelectionColor = new Color (.5f, .5f, 1f);
// Which platform to match for keyboard focus rules.
// If keyboardFocus is Mac, only text entry labels will be able to revcieve the keyboard focus through tabbing. (GUI.TextField, GUI.TextArea, GUILayout.TextField, GUILayout.TextArea)
// If keyboardFocus is Windows, most controls can be tabbed through. If the end user presses the space bar, the focused control will recieve a mouse click.
// If keyboardFocus is Native, the focus rules will follow whatever platform the end user is running on.
// CSRAW public PlatformSelection keyboardFocus { get { return m_KeyboardFocus; } set { m_KeyboardFocus = value; } }
// CSRAW PlatformSelection m_KeyboardFocus = PlatformSelection.Native;
END
// Defines how GUI looks and behaves.
CSRAW [System.Serializable]
CSRAW [ExecuteInEditMode]
CLASS GUISkin : ScriptableObject
CSRAW [SerializeField]
CSRAW Font m_Font;
// *undocumented*
CSRAW public GUISkin()
{
m_CustomStyles = new GUIStyle[1];
}
CSRAW internal void OnEnable()
{
Apply ();
foreach (var style in styles.Values)
style.CreateObjectReferences ();
}
// The default font to use for all styles.
CSRAW public Font font { get { return m_Font; } set { m_Font = value; if (current == this) GUIStyle.SetDefaultFont(m_Font); Apply();} }
CSRAW [SerializeField] //yes the attribute applies to all fields on the line below.
CSRAW GUIStyle m_box, m_button, m_toggle, m_label, m_textField, m_textArea, m_window;
// Style used by default for GUI::ref::Box controls.
CSRAW public GUIStyle box { get { return m_box; } set { m_box = value; Apply (); } }
// Style used by default for GUI::ref::Label controls.
CSRAW public GUIStyle label { get { return m_label; } set { m_label = value; Apply (); } }
// Style used by default for GUI::ref::TextField controls.
CSRAW public GUIStyle textField { get { return m_textField; } set { m_textField = value; Apply (); } }
// Style used by default for GUI::ref::TextArea controls.
CSRAW public GUIStyle textArea { get { return m_textArea; } set { m_textArea = value; Apply (); } }
// Style used by default for GUI::ref::Button controls.
CSRAW public GUIStyle button { get { return m_button; } set { m_button = value; Apply (); } }
// Style used by default for GUI::ref::Toggle controls.
CSRAW public GUIStyle toggle { get { return m_toggle; } set { m_toggle = value; Apply (); } }
// Style used by default for Window controls (SA GUI::ref::Window).
CSRAW public GUIStyle window { get { return m_window; } set { m_window = value; Apply (); } }
CSRAW
[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.
CSRAW 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.
CSRAW 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.
CSRAW 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.
CSRAW public GUIStyle verticalSliderThumb { get { return m_verticalSliderThumb; } set { m_verticalSliderThumb = value; Apply (); } }
CSRAW
[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.
CSRAW 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.
CSRAW 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.
CSRAW 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.
CSRAW public GUIStyle horizontalScrollbarRightButton { get { return m_horizontalScrollbarRightButton; } set { m_horizontalScrollbarRightButton = value; Apply (); } }
CSRAW
[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.
CSRAW 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.
CSRAW 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.
CSRAW 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.
CSRAW public GUIStyle verticalScrollbarDownButton { get { return m_verticalScrollbarDownButton; } set { m_verticalScrollbarDownButton = value; Apply (); } }
// Background style for scroll views.
CSRAW [SerializeField]
CSRAW GUIStyle m_ScrollView;
// Style used by default for the background of ScrollView controls (see GUI::ref::BeginScrollView).
CSRAW public GUIStyle scrollView { get { return m_ScrollView; } set { m_ScrollView = value; Apply (); } }
CSRAW [SerializeField]
CSRAW internal GUIStyle[] m_CustomStyles;
// Array of GUI styles for specific needs.
CSRAW public GUIStyle[] customStyles { get { return m_CustomStyles; } set { m_CustomStyles = value; Apply(); } }
CSRAW [SerializeField]
CSRAW private GUISettings m_Settings = new GUISettings ();
// Generic settings for how controls should behave with this skin.
CSRAW public GUISettings settings { get { return m_Settings; } }
CSRAW internal static GUIStyle ms_Error;
CSRAW internal static GUIStyle error { get { if(ms_Error == null) ms_Error = new GUIStyle(); return ms_Error; } }
CSRAW private Dictionary<string, GUIStyle> styles = null;
CSRAW internal void Apply ()
{
if (m_CustomStyles == null)
Debug.Log("custom styles is null");
BuildStyleCache ();
}
CSRAW 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();
styles = new Dictionary<string, GUIStyle>(
#if !UNITY_FLASH
System.StringComparer.OrdinalIgnoreCase
#endif
);
styles["box"] = m_box; m_box.name = "box";
styles["button"] = m_button; m_button.name = "button";
styles["toggle"] = m_toggle; m_toggle.name = "toggle";
styles["label"] = m_label; m_label.name = "label";
styles["window"] = m_window; m_window.name = "window";
styles["textfield"] = m_textField; m_textField.name = "textfield";
styles["textarea"] = m_textArea; m_textArea.name = "textarea";
styles["horizontalslider"] = m_horizontalSlider; m_horizontalSlider.name = "horizontalslider";
styles["horizontalsliderthumb"] = m_horizontalSliderThumb; m_horizontalSliderThumb.name = "horizontalsliderthumb";
styles["verticalslider"] = m_verticalSlider; m_verticalSlider.name = "verticalslider";
styles["verticalsliderthumb"] = m_verticalSliderThumb; m_verticalSliderThumb.name = "verticalsliderthumb";
styles["horizontalscrollbar"] = m_horizontalScrollbar; m_horizontalScrollbar.name = "horizontalscrollbar";
styles["horizontalscrollbarthumb"] = m_horizontalScrollbarThumb; m_horizontalScrollbarThumb.name = "horizontalscrollbarthumb";
styles["horizontalscrollbarleftbutton"] = m_horizontalScrollbarLeftButton; m_horizontalScrollbarLeftButton.name = "horizontalscrollbarleftbutton";
styles["horizontalscrollbarrightbutton"] = m_horizontalScrollbarRightButton; m_horizontalScrollbarRightButton.name = "horizontalscrollbarrightbutton";
styles["verticalscrollbar"] = m_verticalScrollbar; m_verticalScrollbar.name = "verticalscrollbar";
styles["verticalscrollbarthumb"] = m_verticalScrollbarThumb; m_verticalScrollbarThumb.name = "verticalscrollbarthumb";
styles["verticalscrollbarupbutton"] = m_verticalScrollbarUpButton; m_verticalScrollbarUpButton.name = "verticalscrollbarupbutton";
styles["verticalscrollbardownbutton"] = m_verticalScrollbarDownButton; m_verticalScrollbarDownButton.name = "verticalscrollbardownbutton";
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;
styles[m_CustomStyles[i].name] = m_CustomStyles[i];
}
}
error.stretchHeight = true;
error.normal.textColor = Color.red;
}
// Get a named [[GUIStyle]].
CSRAW 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.
CSRAW public GUIStyle FindStyle (string styleName) {
if (this == null) {
Debug.LogError ("GUISkin is NULL");
return null;
}
if (styles == null)
BuildStyleCache ();
GUIStyle style;
if (styles.TryGetValue(styleName, out style))
return style;
return null;
}
CSRAW
internal delegate void SkinChangedDelegate();
internal static SkinChangedDelegate m_SkinChanged;
// Make this the current skin used by the GUI
static internal GUISkin current;
CSRAW internal void MakeCurrent () {
current = this;
GUIStyle.SetDefaultFont (font);
if (m_SkinChanged != null)
m_SkinChanged();
}
//*undocumented* Documented separately
CSRAW public IEnumerator GetEnumerator ()
{
if (styles == null)
BuildStyleCache ();
return (IEnumerator)styles.Values.GetEnumerator ();
}
END
}
|