Unity编辑器模式下使用协程

导入 Editor Coroutins 插件包

菜单-> Window -> Package Manager ,打开 包管理 面板,导入 Editor Coroutins 插件。

使用案例 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Unity.EditorCoroutines.Editor;

public class Test : MonoBehaviour
{
    [MenuItem("Tools/测试使用协程")]
    private static void menu()
    {
        EditorCoroutineUtility.StartCoroutineOwnerless(testIEnumerator());
    }

    static IEnumerator testIEnumerator()
    {
        for (int i = 0; i < 3; i++)
        {
            Debug.Log("协程调用:"+i);
            yield return new EditorWaitForSeconds(1);
            Debug.Log("WaitForSeconds:" + i);
        }
        Debug.Log("协程调用结束");
    }

}

猜你喜欢

转载自blog.csdn.net/a451319296/article/details/129658911