如何知道由多个对象实现的协同例程何时结束



在我在Unity构建的一个项目中,我有一个大师班(LevelManager(,他会:EventManager.TriggerEvent ("Fade");

监听该事件的多个对象触发一个协同例程1秒钟以"消失"(它们将颜色的alpha通道降低到0(。

发射扳机的大师知道物体已经消失的最好方法是什么?

如果是固定时间,您只需等待一秒钟就可以继续,很容易地使用异步void。

void Awake() {
for (int i = 0; i < 100; i++) { CallAllCoroutines += TestA; }
}
void Update() {
if (Input.GetMouseButtonDown(1)) { MassEventTest(); }
}   
public delegate void CastEvent();
public event CastEvent CallAllCoroutines;
async void MassEventTest() {
Debug.Log("Invoking event");
CallAllCoroutines();
await Task.Delay(1000);
Debug.Log("Can continue");
}
void TestA() { StartCoroutine(TestCoroutine()); }
IEnumerator TestCoroutine() {
Debug.Log("Starting Coroutine");
yield return new WaitForSeconds(1);
Debug.Log("Ending Coroutine");
}

否则,如果你想坚持帧速率行为,你需要保存一个受影响实体的列表(触发协同程序的实体(,并在帧速率的基础上检查它们的状态。

最新更新