我有一些协程:
IEnumerator a(){ /* code */ }
IEnumerator b(){ /* code */ }
IEnumerator c(){ /* code */ }
我想创建一个协程的呼叫a
,b
并c
在平行但等待他们都在继续之前,像完成:
IEnumerator d(){
StartCoroutine(a());
StartCoroutine(b());
StartCoroutine(c());
wait until all of them are over
print("all over");
}
显然,我可以为每个协程使用一个布尔值来保存其当前状态,但是由于此方法不可扩展,因此我希望使用更直接的解决方案。
我使用的方法也很清晰,并且易于使用:
IEnumerator First() { yield return new WaitForSeconds(1f); }
IEnumerator Second() { yield return new WaitForSeconds(2f); }
IEnumerator Third() { yield return new WaitForSeconds(3f); }
IEnumerator d()
{
Coroutine a = StartCoroutine(First());
Coroutine b = StartCoroutine(Second());
Coroutine c = StartCoroutine(Third());
//wait until all of them are over
yield return a;
yield return b;
yield return c;
print("all over");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句