〇、
- 同步等待
- 异步协程
- 同步协程
- 并行协程
一、
同步等待是指,当调用了 yield return yieldInstruction 时,会根据不同的指令的不同,暂时挂起( suspend )协程,等待条件满足后,继续执行协程。
yield return new WaitForSeconds(0.1f);
同步等待的示意图如下:
二、
void Start()
{
StartCoroutine(TestCoroutine());
}
IEnumerator TestCoroutine()
{
print(this + "On TestCoroutine.");
yield return new WaitForSeconds(0.1f);
print("yield return 0.1 and start intextcoroutine On TestCoroutine.");
StartCoroutine(InTestCoroutine());
yield return new WaitForSeconds(0.1f);
print("yield return 0.1 On TestCoroutine. And finish this coroutine.");
}
IEnum