Class EditorCoroutineUtility | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class EditorCoroutineUtility

    Inheritance
    System.Object
    EditorCoroutineUtility
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    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
    System.Collections.IEnumerator routine

    IEnumerator to iterate over.

    System.Object owner

    Object owning the coroutine.

    Returns
    Type Description
    EditorCoroutine

    A handle to an EditorCoroutine.

    Remarks

    Only types that don't inherit from UnityEngine.Object will get collected the next time the GC runs instead of getting null-ed immediately.

    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
    System.Collections.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

    In This Article
    • Methods
      • StartCoroutine(IEnumerator, Object)
      • StartCoroutineOwnerless(IEnumerator)
      • StopCoroutine(EditorCoroutine)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023