diff --git a/src/UniTask/Assets/Editor/EditorRunnerChecker.cs b/src/UniTask/Assets/Editor/EditorRunnerChecker.cs new file mode 100644 index 0000000..ebff07c --- /dev/null +++ b/src/UniTask/Assets/Editor/EditorRunnerChecker.cs @@ -0,0 +1,28 @@ +#if UNITY_EDITOR + +using Cysharp.Threading.Tasks; +using System; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEngine; + +public static class EditorRunnerChecker +{ + [MenuItem("Tools/UniTaskEditorRunnerChecker")] + public static void RunUniTaskAsync() + { + RunCore().Forget(); + } + + static async UniTaskVoid RunCore() + { + Debug.Log("Start, Wait 5 seconds. deltaTime?" + Time.deltaTime); + + await UniTask.Delay(TimeSpan.FromSeconds(5)); + + Debug.Log("End, Wait 5 seconds. deltaTime?" + Time.deltaTime); + } +} + +#endif \ No newline at end of file diff --git a/src/UniTask/Assets/Editor/EditorRunnerChecker.cs.meta b/src/UniTask/Assets/Editor/EditorRunnerChecker.cs.meta new file mode 100644 index 0000000..f6a8be7 --- /dev/null +++ b/src/UniTask/Assets/Editor/EditorRunnerChecker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e51b78c06cb410f42b36e0af9de3b065 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs index 66f44d1..6389d3c 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs @@ -200,27 +200,45 @@ namespace Cysharp.Threading.Tasks #if UNITY_EDITOR + [InitializeOnLoadMethod] static void InitOnEditor() { - //Execute the play mode init method + // Execute the play mode init method Init(); - //register an Editor update delegate, used to forcing playerLoop update + // register an Editor update delegate, used to forcing playerLoop update EditorApplication.update += ForceEditorPlayerLoopUpdate; } + static double beforeCalledTime; + private static void ForceEditorPlayerLoopUpdate() { - if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || - EditorApplication.isUpdating) + if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || EditorApplication.isUpdating) { // Not in Edit mode, don't interfere return; } - //force unity to update PlayerLoop callbacks - EditorApplication.QueuePlayerLoopUpdate(); + // 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(); + } + } } #endif