unity-编辑器协程

unity-编辑器协程


前篇

官方通过 package 支持的版本


使用

  1. 安装 Editor Coroutines

    windows -> package manager 调出包管理界面, 输入 editor coroutines 安装节课

  2. 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    // 1. 命名空间
    using Unity.EditorCoroutines.Editor;

    // 2. 协程方法
    IEnumerator Test_Cor(string name, int age) {
    Debug.LogFormat("--- Test_Cor begin, name: {0}, age: {1}", name, age);
    for (int i = 0; i < 3; i++) {
    Debug.LogFormat("--- Test_Cor doing, cnt: {0}", i);
    yield return new EditorWaitForSeconds(1); // 这个是 editor 的 WaitForSeconds
    }
    Debug.LogFormat("--- Test_Cor begin, name: {0}, age: {1}", name, age);
    }

    // 3. 执行协程
    EditorCoroutineUtility.StartCoroutineOwnerless(Test_Cor("hello", 123));
    • 效果