Last active
June 25, 2020 08:51
-
-
Save jfranmora/2fb7d933df4f62f89441f77e82466c01 to your computer and use it in GitHub Desktop.
Class that permits run coroutines manually, can be useful to run coroutines in Unity Editor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
public static class EditorCoroutineRunner | |
{ | |
private static List<IEnumerator> _coroutineList = new List<IEnumerator>(); | |
static EditorCoroutineRunner() | |
{ | |
EditorApplication.update += ExecuteCoroutine; | |
} | |
private static void ExecuteCoroutine() | |
{ | |
for (var i = 0; i < _coroutineList.Count; i++) | |
{ | |
if (!_coroutineList[i].MoveNext()) | |
{ | |
_coroutineList.RemoveAt(i); | |
i--; | |
} | |
} | |
} | |
public static void StartCoroutine(IEnumerator coroutine) | |
{ | |
_coroutineList.Add(coroutine); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment