diff --git a/Runtime/Async/Coroutine/EditorCoroutineUtility.cs b/Runtime/Async/Coroutine/EditorCoroutineUtility.cs new file mode 100644 index 0000000..47299a8 --- /dev/null +++ b/Runtime/Async/Coroutine/EditorCoroutineUtility.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace StansAssets.Foundation.Async +{ + [InitializeOnLoad] + public class EditorCoroutineUtility + { + private static List EditorCoroutine = new List(); + + public static IEnumerator StartEditorCoroutine(IEnumerator newCor) + { + EditorCoroutine.Add(newCor); + return newCor; + } + + static EditorCoroutineUtility() + { + EditorApplication.update += ExecuteCoroutine; + } + + static int currentExecute = 0; + + private static void ExecuteCoroutine() + { + if (EditorCoroutine.Count <= 0) + { + return; + } + + currentExecute = (currentExecute + 1) % EditorCoroutine.Count; + + bool finish = !EditorCoroutine[currentExecute].MoveNext(); + + if (finish) + { + EditorCoroutine.RemoveAt(currentExecute); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Async/Coroutine/EditorCoroutineUtility.cs.meta b/Runtime/Async/Coroutine/EditorCoroutineUtility.cs.meta new file mode 100644 index 0000000..44bcb5a --- /dev/null +++ b/Runtime/Async/Coroutine/EditorCoroutineUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2a87584501f82b1488dc83c0a4fd36a1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: