@@ -78,7 +78,7 @@ public static int Schedule(Action job, double delayInMilliseconds) {
78
78
scheduledJob = new ScheduledJob {
79
79
Job = job ,
80
80
JobId = nextJobId ,
81
- DelayInMilliseconds = ExecutionEnvironment . InBatchMode ? 0.0 :
81
+ DelayInMilliseconds = ExecutionEnvironment . ExecuteMethodEnabled ? 0.0 :
82
82
delayInMilliseconds
83
83
} ;
84
84
scheduledJobs [ nextJobId ++ ] = scheduledJob ;
@@ -208,9 +208,9 @@ private static bool OnMainThread {
208
208
}
209
209
210
210
/// <summary>
211
- /// Set when the current thread is running ExecuteAll() .
211
+ /// Number of times ExecuteAll() has been called on the current thread .
212
212
/// </summary>
213
- private static bool runningExecuteAll = false ;
213
+ private static int runningExecuteAllCount = 0 ;
214
214
215
215
/// <summary>
216
216
/// Flag which indicates whether any jobs are running on the main thread.
@@ -223,7 +223,10 @@ private static bool OnMainThread {
223
223
/// This property is reset to its' default value after each set of jobs is dispatched.
224
224
/// </summary>
225
225
public static bool ExecuteNow {
226
- get { return ExecutionEnvironment . InBatchMode && ! runningJobs && ! runningExecuteAll ; }
226
+ get {
227
+ return ExecutionEnvironment . ExecuteMethodEnabled && ! runningJobs &&
228
+ runningExecuteAllCount == 0 ;
229
+ }
227
230
}
228
231
229
232
/// <summary>
@@ -234,7 +237,7 @@ static RunOnMainThread() {
234
237
mainThreadId = System . Threading . Thread . CurrentThread . ManagedThreadId ;
235
238
// NOTE: This hooks ExecuteAll on the main thread here and never unregisters as we can't
236
239
// register event handlers on any thread except for the main thread.
237
- if ( ! ExecutionEnvironment . InBatchMode ) OnUpdate += ExecuteAll ;
240
+ OnUpdate += ExecuteAll ;
238
241
}
239
242
240
243
/// <summary>
@@ -261,9 +264,9 @@ private static void AddOnUpdateCallback(EditorApplication.CallbackFunction callb
261
264
Run ( ( ) => {
262
265
EditorApplication . update -= callback ;
263
266
EditorApplication . update += callback ;
264
- // If we're in batch mode , execute the callback now as EditorApplication.update
265
- // will not be signaled if Unity was launched to execute a single method .
266
- if ( ExecutionEnvironment . InBatchMode ) callback ( ) ;
267
+ // If we're in running a single method , execute the callback now as
268
+ // EditorApplication.update will not be signaled.
269
+ if ( ExecutionEnvironment . ExecuteMethodEnabled ) callback ( ) ;
267
270
} ) ;
268
271
}
269
272
@@ -470,10 +473,10 @@ private static void ExecuteAllUnnested(bool allowNested) {
470
473
471
474
// Don't nest job execution on the main thread, return to the last stack frame
472
475
// running ExecuteAll().
473
- if ( runningExecuteAll && ! allowNested ) return ;
476
+ if ( runningExecuteAllCount > 0 && ! allowNested ) return ;
474
477
475
478
RunAction ( ( ) => {
476
- runningExecuteAll = true ;
479
+ runningExecuteAllCount ++ ;
477
480
bool jobsRemaining = true ;
478
481
while ( jobsRemaining ) {
479
482
jobsRemaining = false ;
@@ -484,12 +487,13 @@ private static void ExecuteAllUnnested(bool allowNested) {
484
487
485
488
// Execute polling jobs.
486
489
int remainingJobs = ExecutePollingJobs ( ) ;
487
- // If we're in batch mode, keep on executing until no polling jobs remain.
488
- if ( ExecutionEnvironment . InBatchMode && remainingJobs > 0 ) {
490
+ // If we're in running a single method, keep on executing until no polling jobs
491
+ // remain.
492
+ if ( ExecutionEnvironment . ExecuteMethodEnabled && remainingJobs > 0 ) {
489
493
jobsRemaining = true ;
490
494
}
491
495
}
492
- runningExecuteAll = false ;
496
+ runningExecuteAllCount -- ;
493
497
} ) ;
494
498
}
495
499
}
0 commit comments