@@ -69,8 +69,7 @@ public sealed partial class EditorApplication
6969
7070 static void Internal_ProjectWasLoaded ( )
7171 {
72- if ( projectWasLoaded != null )
73- projectWasLoaded ( ) ;
72+ projectWasLoaded ? . Invoke ( ) ;
7473 }
7574
7675 [ RequiredByNativeCode ]
@@ -115,11 +114,8 @@ static bool Internal_EditorApplicationWantsToQuit()
115114
116115 static void Internal_EditorApplicationQuit ( )
117116 {
118- if ( quitting != null )
119- quitting ( ) ;
120-
121- if ( editorApplicationQuit != null )
122- editorApplicationQuit ( ) ;
117+ quitting ? . Invoke ( ) ;
118+ editorApplicationQuit ? . Invoke ( ) ;
123119 }
124120
125121 // Delegate to be called for every visible list item in the ProjectWindow on every OnGUI event.
@@ -154,17 +150,15 @@ public static void RepaintAnimationWindow()
154150 // Can be used to ensure repaint of the HierarchyWindow.
155151 public static void RepaintHierarchyWindow ( )
156152 {
157- if ( refreshHierarchy != null )
158- refreshHierarchy ( ) ;
153+ refreshHierarchy ? . Invoke ( ) ;
159154 }
160155
161156 // Delegate for dirtying hierarchy sorting.
162157 internal static CallbackFunction dirtyHierarchySorting ;
163158
164159 public static void DirtyHierarchyWindowSorting ( )
165160 {
166- if ( dirtyHierarchySorting != null )
167- dirtyHierarchySorting ( ) ;
161+ dirtyHierarchySorting ? . Invoke ( ) ;
168162 }
169163
170164 // Delegate to be called from [[EditorApplication]] callbacks.
@@ -182,6 +176,22 @@ public static void DirtyHierarchyWindowSorting()
182176
183177 public static CallbackFunction delayCall ;
184178
179+ internal static void CallDelayed ( CallbackFunction action , double delaySeconds = 0.0f )
180+ {
181+ var startTime = DateTime . Now ;
182+ CallbackFunction delayedHandler = null ;
183+ delayedHandler = new CallbackFunction ( ( ) =>
184+ {
185+ if ( ( DateTime . Now - startTime ) . TotalSeconds < delaySeconds )
186+ return ;
187+ update -= delayedHandler ;
188+ action ( ) ;
189+ } ) ;
190+ update += delayedHandler ;
191+ if ( delaySeconds == 0f )
192+ SignalTick ( ) ;
193+ }
194+
185195 // Each time an object is (or a group of objects are) created, renamed, parented, unparented or destroyed this callback is raised.
186196 public static event Action hierarchyChanged ;
187197
@@ -306,40 +316,39 @@ internal static string BuildMainWindowTitle()
306316 static int m_UpdateHash ;
307317 static Delegate [ ] m_UpdateInvocationList ;
308318
319+ [ RequiredByNativeCode ]
309320 static void Internal_CallUpdateFunctions ( )
310321 {
311- if ( update != null )
322+ if ( update == null )
323+ return ;
324+ if ( Profiler . enabled && ! ProfilerDriver . deepProfiling )
312325 {
313- if ( Profiler . enabled && ! ProfilerDriver . deepProfiling )
326+ var currentUpdateHash = update . GetHashCode ( ) ;
327+ if ( currentUpdateHash != m_UpdateHash )
314328 {
315- var currentUpdateHash = update . GetHashCode ( ) ;
316- if ( currentUpdateHash != m_UpdateHash )
317- {
318- m_UpdateInvocationList = update . GetInvocationList ( ) ;
319- m_UpdateHash = currentUpdateHash ;
320- }
321- foreach ( var cb in m_UpdateInvocationList )
322- {
323- var marker = new ProfilerMarker ( cb . Method . Name ) ;
324- marker . Begin ( ) ;
325- cb . DynamicInvoke ( null ) ;
326- marker . End ( ) ;
327- }
329+ m_UpdateInvocationList = update . GetInvocationList ( ) ;
330+ m_UpdateHash = currentUpdateHash ;
328331 }
329- else
332+ foreach ( var cb in m_UpdateInvocationList )
330333 {
331- update . Invoke ( ) ;
334+ var marker = new ProfilerMarker ( cb . Method . Name ) ;
335+ marker . Begin ( ) ;
336+ cb . DynamicInvoke ( null ) ;
337+ marker . End ( ) ;
332338 }
333339 }
340+ else
341+ {
342+ update . Invoke ( ) ;
343+ }
334344 }
335345
346+ [ RequiredByNativeCode ]
336347 static void Internal_CallDelayFunctions ( )
337348 {
338349 CallbackFunction delay = delayCall ;
339350 delayCall = null ;
340-
341- if ( delay != null )
342- delay ( ) ;
351+ delay ? . Invoke ( ) ;
343352 }
344353
345354 static void Internal_SwitchSkin ( )
@@ -356,95 +365,62 @@ internal static void RequestRepaintAllViews()
356365 static void Internal_CallHierarchyHasChanged ( )
357366 {
358367 #pragma warning disable 618
359- if ( hierarchyWindowChanged != null )
360- hierarchyWindowChanged ( ) ;
368+ hierarchyWindowChanged ? . Invoke ( ) ;
361369 #pragma warning restore 618
362370
363- if ( hierarchyChanged != null )
364- hierarchyChanged ( ) ;
371+ hierarchyChanged ? . Invoke ( ) ;
365372 }
366373
367374 static void Internal_CallProjectHasChanged ( )
368375 {
369376 #pragma warning disable 618
370- if ( projectWindowChanged != null )
371- projectWindowChanged ( ) ;
377+ projectWindowChanged ? . Invoke ( ) ;
372378 #pragma warning restore 618
373379
374- if ( projectChanged != null )
375- projectChanged ( ) ;
380+ projectChanged ? . Invoke ( ) ;
376381 }
377382
378383 internal static void Internal_CallSearchHasChanged ( )
379384 {
380- if ( searchChanged != null )
381- searchChanged ( ) ;
385+ searchChanged ? . Invoke ( ) ;
382386 }
383387
384388 internal static void Internal_CallAssetLabelsHaveChanged ( )
385389 {
386- if ( assetLabelsChanged != null )
387- assetLabelsChanged ( ) ;
390+ assetLabelsChanged ? . Invoke ( ) ;
388391 }
389392
390393 internal static void Internal_CallAssetBundleNameChanged ( )
391394 {
392- if ( assetBundleNameChanged != null )
393- assetBundleNameChanged ( ) ;
394- }
395-
396- // Single use case for now ONLY!
397- internal static void CallDelayed ( CallbackFunction function , float timeFromNow )
398- {
399- delayedCallback = function ;
400- s_DelayedCallbackTime = Time . realtimeSinceStartup + timeFromNow ;
401- update += CheckCallDelayed ;
402- }
403-
404- static CallbackFunction delayedCallback ;
405- static float s_DelayedCallbackTime = 0.0f ;
406-
407- static void CheckCallDelayed ( )
408- {
409- if ( Time . realtimeSinceStartup > s_DelayedCallbackTime )
410- {
411- update -= CheckCallDelayed ;
412- delayedCallback ( ) ;
413- }
395+ assetBundleNameChanged ? . Invoke ( ) ;
414396 }
415397
416398 static void Internal_PauseStateChanged ( PauseState state )
417399 {
418400 #pragma warning disable 618
419- if ( playmodeStateChanged != null )
420- playmodeStateChanged ( ) ;
401+ playmodeStateChanged ? . Invoke ( ) ;
421402 #pragma warning restore 618
422403
423- if ( pauseStateChanged != null )
424- pauseStateChanged ( state ) ;
404+ pauseStateChanged ? . Invoke ( state ) ;
425405 }
426406
427407 static void Internal_PlayModeStateChanged ( PlayModeStateChange state )
428408 {
429409 #pragma warning disable 618
430- if ( playmodeStateChanged != null )
431- playmodeStateChanged ( ) ;
410+ playmodeStateChanged ? . Invoke ( ) ;
432411 #pragma warning restore 618
433412
434- if ( playModeStateChanged != null )
435- playModeStateChanged ( state ) ;
413+ playModeStateChanged ? . Invoke ( state ) ;
436414 }
437415
438416 static void Internal_CallKeyboardModifiersChanged ( )
439417 {
440- if ( modifierKeysChanged != null )
441- modifierKeysChanged ( ) ;
418+ modifierKeysChanged ? . Invoke ( ) ;
442419 }
443420
444421 static void Internal_CallWindowsReordered ( )
445422 {
446- if ( windowsReordered != null )
447- windowsReordered ( ) ;
423+ windowsReordered ? . Invoke ( ) ;
448424 }
449425
450426 [ RequiredByNativeCode ]
@@ -458,8 +434,7 @@ static bool DoPressedKeysTriggerAnyShortcutHandler()
458434 [ RequiredByNativeCode ]
459435 static void Internal_CallGlobalEventHandler ( )
460436 {
461- if ( globalEventHandler != null )
462- globalEventHandler ( ) ;
437+ globalEventHandler ? . Invoke ( ) ;
463438
464439 // Ensure this is called last in order to make sure no null current events are passed to other handlers
465440 WindowLayout . MaximizeGestureHandler ( ) ;
0 commit comments