Fixed edit mode, clear continuations and runners on run mode change, edit mode unit tests

This commit is contained in:
Antonio
2019-09-09 13:07:56 +02:00
committed by Antonio Ruggiero
parent 50ba93f951
commit ecf6c1fba5
13 changed files with 1326 additions and 21 deletions

View File

@@ -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];