Class EditorCoroutineUtility
Namespace: Unity.EditorCoroutines.Editor
Syntax
public static class EditorCoroutineUtility
Methods
StartCoroutine(IEnumerator, Object)
Starts an EditorCoroutine with the specified owner object. If the garbage collector collects the owner object, while the resulting coroutine is still executing, the coroutine will stop running.
using System.Collections;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
public class ExampleWindow : EditorWindow
{
int m_Updates = 0;
void OnEnable()
{
EditorCoroutineUtility.StartCoroutine(CountEditorUpdates(), this);
}
IEnumerator CountEditorUpdates()
{
while (true)
{
++m_Updates;
yield return null;
}
}
}
Declaration
public static EditorCoroutine StartCoroutine(IEnumerator routine, object owner)
Parameters
Type | Name | Description |
---|---|---|
IEnumerator | routine | IEnumerator to iterate over. |
Object | owner | Object owning the coroutine. |
Returns
Type | Description |
---|---|
EditorCoroutine | A handle to an EditorCoroutine. |
Remarks
Only types that don't inherit from
StartCoroutineOwnerless(IEnumerator)
This method starts an EditorCoroutine without an owning object. The EditorCoroutine runs until it completes or is canceled using StopCoroutine(EditorCoroutine).
using System.Collections;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;
public class ExampleWindow : EditorWindow
{
void OnEnable()
{
EditorCoroutineUtility.StartCoroutineOwnerless(LogTimeSinceStartup());
}
IEnumerator LogTimeSinceStartup()
{
while (true)
{
Debug.LogFormat("Time since startup: {0} s", Time.realtimeSinceStartup);
yield return null;
}
}
}
Declaration
public static EditorCoroutine StartCoroutineOwnerless(IEnumerator routine)
Parameters
Type | Name | Description |
---|---|---|
IEnumerator | routine | Generator function to execute. |
Returns
Type | Description |
---|---|
EditorCoroutine | A handle to an EditorCoroutine |
StopCoroutine(EditorCoroutine)
Immediately stop an EditorCoroutine. This method is safe to call on an already completed EditorCoroutine.
using System.Collections;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;
public class ExampleWindow : EditorWindow
{
EditorCoroutine m_LoggerCoroutine;
void OnEnable()
{
m_LoggerCoroutine = EditorCoroutineUtility.StartCoroutineOwnerless(LogRunning());
}
void OnDisable()
{
EditorCoroutineUtility.StopCoroutine(m_LoggerCoroutine);
}
IEnumerator LogRunning()
{
while (true)
{
Debug.Log("Running");
yield return null;
}
}
}
Declaration
public static void StopCoroutine(EditorCoroutine coroutine)
Parameters
Type | Name | Description |
---|---|---|
EditorCoroutine | coroutine | A handle to an EditorCoroutine |