Unity – Coroutine in Editor mode

Classé dans : 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);
}
}

}

Also posted in that thread

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *