我知道Unity3D StartCoroutine调用了一个与StartCoroutine在同一线程上运行的函数,但是被调用的函数什么时候返回到原始调用者?
我在互联网上查找了一个很好的 Unity3D Coroutine 示例,但找不到完整的示例。有一个很好的解释 http://unitygems.com/coroutines/由 UnityGems 提供,但即使他们的示例也是不完整的。所以我写了自己的例子。
This:
using UnityEngine;
using System.Collections;
public class MainCamera: MonoBehaviour {
void Start () {
Debug.Log ("About to StartCoroutine");
StartCoroutine(TestCoroutine());
Debug.Log ("Back from StartCoroutine");
}
IEnumerator TestCoroutine(){
Debug.Log ("about to yield return WaitForSeconds(1)");
yield return new WaitForSeconds(1);
Debug.Log ("Just waited 1 second");
yield return new WaitForSeconds(1);
Debug.Log ("Just waited another second");
yield break;
Debug.Log ("You'll never see this"); // produces a dead code warning
}
}
产生以下输出:
About to StartCoroutine
about to yield return WaitForSeconds(1)
Back from StartCoroutine
Just waited 1 second
Just waited another second
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)