mirror of https://github.com/Cysharp/UniTask
add EditorUpdate special timing to support EditorApplication.update tick
parent
c1042b32b7
commit
448fc8c1de
|
@ -76,6 +76,10 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
switch (timing)
|
switch (timing)
|
||||||
{
|
{
|
||||||
|
case PlayerLoopTiming.EditorUpdate:
|
||||||
|
EditorUpdate();
|
||||||
|
break;
|
||||||
|
|
||||||
case PlayerLoopTiming.Initialization:
|
case PlayerLoopTiming.Initialization:
|
||||||
Initialization();
|
Initialization();
|
||||||
break;
|
break;
|
||||||
|
@ -134,6 +138,7 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorUpdate() => RunCore();
|
||||||
void Initialization() => RunCore();
|
void Initialization() => RunCore();
|
||||||
void LastInitialization() => RunCore();
|
void LastInitialization() => RunCore();
|
||||||
void EarlyUpdate() => RunCore();
|
void EarlyUpdate() => RunCore();
|
||||||
|
|
|
@ -70,6 +70,8 @@ namespace Cysharp.Threading.Tasks
|
||||||
|
|
||||||
public enum PlayerLoopTiming
|
public enum PlayerLoopTiming
|
||||||
{
|
{
|
||||||
|
EditorUpdate = -1,
|
||||||
|
|
||||||
Initialization = 0,
|
Initialization = 0,
|
||||||
LastInitialization = 1,
|
LastInitialization = 1,
|
||||||
|
|
||||||
|
@ -192,6 +194,10 @@ namespace Cysharp.Threading.Tasks
|
||||||
static SynchronizationContext unitySynchronizationContext;
|
static SynchronizationContext unitySynchronizationContext;
|
||||||
static ContinuationQueue[] yielders;
|
static ContinuationQueue[] yielders;
|
||||||
static PlayerLoopRunner[] runners;
|
static PlayerLoopRunner[] runners;
|
||||||
|
|
||||||
|
static ContinuationQueue editorYielder;
|
||||||
|
static PlayerLoopRunner editorRunner;
|
||||||
|
|
||||||
internal static bool IsEditorApplicationQuitting { get; private set; }
|
internal static bool IsEditorApplicationQuitting { get; private set; }
|
||||||
static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem,
|
static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem,
|
||||||
bool injectOnFirst,
|
bool injectOnFirst,
|
||||||
|
@ -332,31 +338,8 @@ namespace Cysharp.Threading.Tasks
|
||||||
|
|
||||||
private static void ForceEditorPlayerLoopUpdate()
|
private static void ForceEditorPlayerLoopUpdate()
|
||||||
{
|
{
|
||||||
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating)
|
editorYielder?.Run();
|
||||||
{
|
editorRunner?.Run();
|
||||||
// Not in Edit mode, don't interfere
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// EditorApplication.QueuePlayerLoopUpdate causes performance issue, don't call directly.
|
|
||||||
// EditorApplication.QueuePlayerLoopUpdate();
|
|
||||||
|
|
||||||
if (yielders != null)
|
|
||||||
{
|
|
||||||
foreach (var item in yielders)
|
|
||||||
{
|
|
||||||
if (item != null) item.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (runners != null)
|
|
||||||
{
|
|
||||||
foreach (var item in runners)
|
|
||||||
{
|
|
||||||
if (item != null) item.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UniTaskSynchronizationContext.Run();
|
UniTaskSynchronizationContext.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,6 +459,10 @@ namespace Cysharp.Threading.Tasks
|
||||||
InjectPlayerLoopTimings.LastTimeUpdate, 15, false,
|
InjectPlayerLoopTimings.LastTimeUpdate, 15, false,
|
||||||
typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldTimeUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastTimeUpdate), PlayerLoopTiming.LastTimeUpdate);
|
typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldTimeUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastTimeUpdate), PlayerLoopTiming.LastTimeUpdate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Editor Update
|
||||||
|
editorYielder = new ContinuationQueue(PlayerLoopTiming.EditorUpdate);
|
||||||
|
editorRunner = new PlayerLoopRunner(PlayerLoopTiming.EditorUpdate);
|
||||||
|
|
||||||
// Insert UniTaskSynchronizationContext to Update loop
|
// Insert UniTaskSynchronizationContext to Update loop
|
||||||
var i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Update));
|
var i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Update));
|
||||||
|
@ -487,7 +474,10 @@ namespace Cysharp.Threading.Tasks
|
||||||
|
|
||||||
public static void AddAction(PlayerLoopTiming timing, IPlayerLoopItem action)
|
public static void AddAction(PlayerLoopTiming timing, IPlayerLoopItem action)
|
||||||
{
|
{
|
||||||
var runner = runners[(int)timing];
|
var runner = timing == PlayerLoopTiming.EditorUpdate
|
||||||
|
? editorRunner
|
||||||
|
: runners[(int)timing];
|
||||||
|
|
||||||
if (runner == null)
|
if (runner == null)
|
||||||
{
|
{
|
||||||
ThrowInvalidLoopTiming(timing);
|
ThrowInvalidLoopTiming(timing);
|
||||||
|
@ -502,7 +492,7 @@ namespace Cysharp.Threading.Tasks
|
||||||
|
|
||||||
public static void AddContinuation(PlayerLoopTiming timing, Action continuation)
|
public static void AddContinuation(PlayerLoopTiming timing, Action continuation)
|
||||||
{
|
{
|
||||||
var q = yielders[(int)timing];
|
var q = timing == PlayerLoopTiming.EditorUpdate ? editorYielder : yielders[(int)timing];
|
||||||
if (q == null)
|
if (q == null)
|
||||||
{
|
{
|
||||||
ThrowInvalidLoopTiming(timing);
|
ThrowInvalidLoopTiming(timing);
|
||||||
|
|
Loading…
Reference in New Issue