From f82c762263215d326bb86e2493908267785e756a Mon Sep 17 00:00:00 2001 From: neuecc Date: Fri, 28 Jun 2019 20:41:04 +0900 Subject: [PATCH] Prevent UnitTasks from continuing after exiting play mode #22 --- Assets/Tests/AsyncTest.cs | 2 -- .../UniRx.Async/EnumeratorAsyncExtensions.cs | 8 -------- Assets/UniRx.Async/PlayerLoopHelper.cs | 20 +++++++++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Assets/Tests/AsyncTest.cs b/Assets/Tests/AsyncTest.cs index d0931bc..b6f1833 100644 --- a/Assets/Tests/AsyncTest.cs +++ b/Assets/Tests/AsyncTest.cs @@ -195,7 +195,6 @@ namespace UniRx.AsyncTests var currentThreadId = Thread.CurrentThread.ManagedThreadId; - UnityEngine.Debug.Log("Before:" + currentThreadId); await UniTask.SwitchToThreadPool(); @@ -209,7 +208,6 @@ namespace UniRx.AsyncTests var switchedThreadId = Thread.CurrentThread.ManagedThreadId; - UnityEngine.Debug.Log("After:" + switchedThreadId); currentThreadId.Should().NotBe(switchedThreadId); diff --git a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs index 62b968e..0f6c5a6 100644 --- a/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs +++ b/Assets/UniRx.Async/EnumeratorAsyncExtensions.cs @@ -232,14 +232,6 @@ namespace UniRx.Async }; } - static IEnumerator UnwrapEnumerator(IEnumerator enumerator) - { - while (enumerator.MoveNext()) - { - yield return null; - } - } - static IEnumerator UnwrapWaitAsyncOperation(AsyncOperation asyncOperation) { while (!asyncOperation.isDone) diff --git a/Assets/UniRx.Async/PlayerLoopHelper.cs b/Assets/UniRx.Async/PlayerLoopHelper.cs index 7d2c8bb..326edf7 100644 --- a/Assets/UniRx.Async/PlayerLoopHelper.cs +++ b/Assets/UniRx.Async/PlayerLoopHelper.cs @@ -67,13 +67,33 @@ namespace UniRx.Async 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];