首先这是我想做的:
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 yield功能。
还有没有匿名IEnumerators的方法,可以达到与上述相同的效果?