Unity – Coroutine in Editor mode

posted in: Non classé, Unity | 0

As part of EasyLocalization work in progress, here is what I found to execute coroutine while in editor :

 

[InitializeOnLoad]
public class EasyLocalization_Script
{
// This is my callable function
public static IEnumerator StartCoroutine(IEnumerator newCorou)
{
CoroutineInProgress.Add(newCorou);
return newCorou;
}
 
/// <summary>
/// Coroutine to execute. Manage by the EasyLocalization_script
/// </summary>
private static List<IEnumerator> CoroutineInProgress = new List<IEnumerator>();
private static EasyLocalization_Script()
{
EditorApplication.update += ExecuteCoroutine;
}
 
static int currentExecute = 0;
private static void ExecuteCoroutine()
{
if (CoroutineInProgress.Count <= 0)
{
// Debug.LogWarning("ping");
return;
}
 
// Debug.LogWarning("exec");
 
currentExecute = (currentExecute + 1) % CoroutineInProgress.Count;
 
bool finish = !CoroutineInProgress[currentExecute].MoveNext();
 
if (finish)
{
CoroutineInProgress.RemoveAt(currentExecute);
}
}
 
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *