代码之家  ›  专栏  ›  技术社区  ›  T. Grumser

匿名协同程序

  •  0
  • T. Grumser  · 技术社区  · 7 年前

    首先,我想做的是:

    delegate IEnumerator EnemySpawningRoutine();
    
    EnemySpawningRoutine[] enemySpawners = new EnemySpawningRoutine[] {
        () => {
            //variables
            //spawn
            yield return new WaitForSeconds(3f);
            //complex stuff
            //more spawning
        },
        () => {
            //same as above
        }
    };
    
    IEnumerator EnemySpawningRoutine() {
        IEnumerator currentSpawnRoutine;
        while(isGameRunning) {
            currentSpawnRoutine = //choose one of enemySpawners
            StartCoroutine(currentSpawnRoutine);
            yield return new WaitUntil(() => {
                //return true if all enemies are dead or something like that.
            });
        }
    }
    

    不幸的是,这似乎是不可能的,因为委托或匿名函数不支持yield-return功能。

    有没有其他方法可以在不使用匿名IEnumerator的情况下达到上述效果?

    0 回复  |  直到 7 年前