-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathEditorApplication.cs
More file actions
339 lines (269 loc) · 10.9 KB
/
EditorApplication.cs
File metadata and controls
339 lines (269 loc) · 10.9 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
// 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.Generic;
using System.Linq;
using System.Text;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Scripting;
using UnityEditorInternal;
namespace UnityEditor
{
public enum PlayModeStateChange
{
EnteredEditMode,
ExitingEditMode,
EnteredPlayMode,
ExitingPlayMode,
}
// Must be kept in sync with enum in ScriptCompilationPipeline.h
internal enum ScriptChangesDuringPlayOptions
{
RecompileAndContinuePlaying = 0,
RecompileAfterFinishedPlaying = 1,
StopPlayingAndRecompile = 2
}
public enum PauseState
{
Paused,
Unpaused,
}
public sealed partial class EditorApplication
{
internal static UnityAction projectWasLoaded;
internal static UnityAction editorApplicationQuit;
static void Internal_ProjectWasLoaded()
{
if (projectWasLoaded != null)
projectWasLoaded();
}
[RequiredByNativeCode]
static bool Internal_EditorApplicationWantsToQuit()
{
if (wantsToQuit == null)
return true;
foreach (Func<bool> continueQuit in wantsToQuit.GetInvocationList())
{
try
{
if (!continueQuit())
return false;
}
catch (Exception exception)
{
Debug.LogWarningFormat("EditorApplication.wantsToQuit: Exception raised during quit event."
+ Environment.NewLine +
"Check the exception error's callstack to find out which event handler threw the exception.");
Debug.LogException(exception);
if (InternalEditorUtility.isHumanControllingUs)
{
string st = exception.StackTrace;
StringBuilder dialogText = new StringBuilder("An exception was thrown here:");
dialogText.AppendLine(Environment.NewLine);
dialogText.AppendLine(st.Substring(0, st.IndexOf(Environment.NewLine)));
bool abortQuit = !EditorUtility.DisplayDialog("Error while quitting",
dialogText.ToString(),
"Ignore", "Cancel Quit");
if (abortQuit)
return false;
}
}
}
return true;
}
static void Internal_EditorApplicationQuit()
{
if (quitting != null)
quitting();
if (editorApplicationQuit != null)
editorApplicationQuit();
}
// Delegate to be called for every visible list item in the ProjectWindow on every OnGUI event.
public delegate void ProjectWindowItemCallback(string guid, Rect selectionRect);
// Delegate for OnGUI events for every visible list item in the ProjectWindow.
public static ProjectWindowItemCallback projectWindowItemOnGUI;
// Can be used to ensure repaint of the ProjectWindow.
public static void RepaintProjectWindow()
{
foreach (ProjectBrowser pb in ProjectBrowser.GetAllProjectBrowsers())
pb.Repaint();
}
// Can be used to ensure repaint of AnimationWindow
public static void RepaintAnimationWindow()
{
foreach (AnimEditor animEditor in AnimEditor.GetAllAnimationWindows())
animEditor.Repaint();
}
// Delegate to be called for every visible list item in the HierarchyWindow on every OnGUI event.
public delegate void HierarchyWindowItemCallback(int instanceID, Rect selectionRect);
// Delegate for OnGUI events for every visible list item in the HierarchyWindow.
public static HierarchyWindowItemCallback hierarchyWindowItemOnGUI;
// Delegate for refreshing hierarchies.
internal static CallbackFunction refreshHierarchy;
// Can be used to ensure repaint of the HierarchyWindow.
public static void RepaintHierarchyWindow()
{
if (refreshHierarchy != null)
refreshHierarchy();
}
// Delegate for dirtying hierarchy sorting.
internal static CallbackFunction dirtyHierarchySorting;
public static void DirtyHierarchyWindowSorting()
{
if (dirtyHierarchySorting != null)
dirtyHierarchySorting();
}
// Delegate to be called from [[EditorApplication]] callbacks.
public delegate void CallbackFunction();
// Delegate to be called from [[EditorApplication]] contextual inspector callbacks.
public delegate void SerializedPropertyCallbackFunction(GenericMenu menu, SerializedProperty property);
// Delegate for generic updates.
public static CallbackFunction update;
public static event Func<bool> wantsToQuit;
public static event Action quitting;
public static CallbackFunction delayCall;
// Each time an object is (or a group of objects are) created, renamed, parented, unparented or destroyed this callback is raised.
public static event Action hierarchyChanged;
[Obsolete("Use EditorApplication.hierarchyChanged")]
public static CallbackFunction hierarchyWindowChanged;
public static event Action projectChanged;
[Obsolete("Use EditorApplication.projectChanged")]
public static CallbackFunction projectWindowChanged;
public static CallbackFunction searchChanged;
internal static CallbackFunction assetLabelsChanged;
internal static CallbackFunction assetBundleNameChanged;
// Delegate for changed keyboard modifier keys.
public static CallbackFunction modifierKeysChanged;
public static event Action<PauseState> pauseStateChanged;
public static event Action<PlayModeStateChange> playModeStateChanged;
[Obsolete("Use EditorApplication.playModeStateChanged and/or EditorApplication.pauseStateChanged")]
public static CallbackFunction playmodeStateChanged;
// Global key up/down event that was not handled by anyone
internal static CallbackFunction globalEventHandler;
// Returns true when the pressed keys are defined in the Trigger
internal static Func<bool> doPressedKeysTriggerAnyShortcut;
// Windows were reordered
internal static CallbackFunction windowsReordered;
// Global contextual menus for inspector values
public static SerializedPropertyCallbackFunction contextualPropertyMenu;
static void Internal_CallUpdateFunctions()
{
if (update != null)
update();
}
static void Internal_CallDelayFunctions()
{
CallbackFunction delay = delayCall;
delayCall = null;
if (delay != null)
delay();
}
static void Internal_SwitchSkin()
{
EditorGUIUtility.Internal_SwitchSkin();
}
internal static void RequestRepaintAllViews()
{
foreach (GUIView view in Resources.FindObjectsOfTypeAll(typeof(GUIView)))
view.Repaint();
}
static void Internal_CallHierarchyHasChanged()
{
#pragma warning disable 618
if (hierarchyWindowChanged != null)
hierarchyWindowChanged();
#pragma warning restore 618
if (hierarchyChanged != null)
hierarchyChanged();
}
static void Internal_CallProjectHasChanged()
{
#pragma warning disable 618
if (projectWindowChanged != null)
projectWindowChanged();
#pragma warning restore 618
if (projectChanged != null)
projectChanged();
}
internal static void Internal_CallSearchHasChanged()
{
if (searchChanged != null)
searchChanged();
}
internal static void Internal_CallAssetLabelsHaveChanged()
{
if (assetLabelsChanged != null)
assetLabelsChanged();
}
internal static void Internal_CallAssetBundleNameChanged()
{
if (assetBundleNameChanged != null)
assetBundleNameChanged();
}
// Single use case for now ONLY!
internal static void CallDelayed(CallbackFunction function, float timeFromNow)
{
delayedCallback = function;
s_DelayedCallbackTime = Time.realtimeSinceStartup + timeFromNow;
update += CheckCallDelayed;
}
static CallbackFunction delayedCallback;
static float s_DelayedCallbackTime = 0.0f;
static void CheckCallDelayed()
{
if (Time.realtimeSinceStartup > s_DelayedCallbackTime)
{
update -= CheckCallDelayed;
delayedCallback();
}
}
static void Internal_PauseStateChanged(PauseState state)
{
#pragma warning disable 618
if (playmodeStateChanged != null)
playmodeStateChanged();
#pragma warning restore 618
if (pauseStateChanged != null)
pauseStateChanged(state);
}
static void Internal_PlayModeStateChanged(PlayModeStateChange state)
{
#pragma warning disable 618
if (playmodeStateChanged != null)
playmodeStateChanged();
#pragma warning restore 618
if (playModeStateChanged != null)
playModeStateChanged(state);
}
static void Internal_CallKeyboardModifiersChanged()
{
if (modifierKeysChanged != null)
modifierKeysChanged();
}
static void Internal_CallWindowsReordered()
{
if (windowsReordered != null)
windowsReordered();
}
[RequiredByNativeCode]
static bool DoPressedKeysTriggerAnyShortcutHandler()
{
if (doPressedKeysTriggerAnyShortcut != null)
return doPressedKeysTriggerAnyShortcut();
return false;
}
[RequiredByNativeCode]
static void Internal_CallGlobalEventHandler()
{
if (globalEventHandler != null)
globalEventHandler();
// Ensure this is called last in order to make sure no null current events are passed to other handlers
WindowLayout.MaximizeGestureHandler();
Event.current = null;
}
}
}