mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-16 20:20:45 +00:00
Fixed edit mode, clear continuations and runners on run mode change, edit mode unit tests
This commit is contained in:
committed by
Antonio Ruggiero
parent
50ba93f951
commit
ecf6c1fba5
@@ -13,6 +13,10 @@ using UnityEngine.LowLevel;
|
||||
using UnityEngine.Experimental.LowLevel;
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public static class UniTaskLoopRunners
|
||||
@@ -62,38 +66,30 @@ namespace UniRx.Async
|
||||
static ContinuationQueue[] yielders;
|
||||
static PlayerLoopRunner[] runners;
|
||||
|
||||
static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
|
||||
static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType,
|
||||
ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
|
||||
{
|
||||
EditorApplication.playModeStateChanged += (state) =>
|
||||
{
|
||||
if (state==PlayModeStateChange.EnteredEditMode || state==PlayModeStateChange.EnteredPlayMode) return;
|
||||
|
||||
if (runner != null)
|
||||
runner.Clear();
|
||||
if (cq != null)
|
||||
cq.Clear();
|
||||
};
|
||||
|
||||
|
||||
var yieldLoop = new PlayerLoopSystem
|
||||
{
|
||||
type = loopRunnerYieldType,
|
||||
#if UNITY_EDITOR
|
||||
updateDelegate = () =>
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
cq.Run();
|
||||
}
|
||||
}
|
||||
#else
|
||||
updateDelegate = cq.Run
|
||||
#endif
|
||||
};
|
||||
|
||||
var runnerLoop = new PlayerLoopSystem
|
||||
{
|
||||
type = loopRunnerType,
|
||||
#if UNITY_EDITOR
|
||||
updateDelegate = () =>
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
runner.Run();
|
||||
}
|
||||
}
|
||||
#else
|
||||
updateDelegate = runner.Run
|
||||
#endif
|
||||
};
|
||||
|
||||
var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2];
|
||||
@@ -122,6 +118,31 @@ namespace UniRx.Async
|
||||
Initialize(ref playerLoop);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoadMethod]
|
||||
static void InitOnEditor()
|
||||
{
|
||||
Init();
|
||||
|
||||
EditorApplication.update += ForceEditorPlayerLoopUpdate;
|
||||
}
|
||||
|
||||
|
||||
private static void ForceEditorPlayerLoopUpdate()
|
||||
{
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling ||
|
||||
EditorApplication.isUpdating)
|
||||
{
|
||||
// Not in Edit mode, don't interfere
|
||||
return;
|
||||
}
|
||||
|
||||
EditorApplication.QueuePlayerLoopUpdate();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
public static void Initialize(ref PlayerLoopSystem playerLoop)
|
||||
{
|
||||
yielders = new ContinuationQueue[7];
|
||||
|
||||
Reference in New Issue
Block a user