日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

unity update 协程_Unity协程,停止协程及yield return使用_019

發(fā)布時間:2024/9/19 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 unity update 协程_Unity协程,停止协程及yield return使用_019 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

public void Start()

//開啟協(xié)程

Coroutine testCoroutine = StartCoroutine(Test());

//停止指定協(xié)程

StopCoroutine(testCoroutine);

//協(xié)程可以同時開啟多個

StartCoroutine("Test");

//經(jīng)實測,StopCoroutine("Test")只能停止StartCoroutine("Test")開啟的協(xié)程,對StartCoroutine(Test())開啟的協(xié)程無效

StopCoroutine("Test");

//停止本腳本內(nèi)所有協(xié)程

StopAllCoroutines();

IEnumerator Test()

//等待下一幀Update之后,繼續(xù)執(zhí)行后續(xù)代碼

yield return null;

//等待在所有相機和GUI渲染之后,直到幀結(jié)束,繼續(xù)執(zhí)行后續(xù)代碼

yield return new WaitForEndOfFrame();

//等待下一個FixedUpdate之后,繼續(xù)執(zhí)行后續(xù)代碼

yield return new WaitForFixedUpdate();

//等待3秒之后,繼續(xù)執(zhí)行后續(xù)代碼,使用縮放時間暫停協(xié)程執(zhí)行達到給定的秒數(shù)

yield return new WaitForSeconds(3.0f);

//等待3秒之后,繼續(xù)執(zhí)行后續(xù)代碼,使用未縮放的時間暫停協(xié)程執(zhí)行達到給定的秒數(shù)

yield return new WaitForSecondsRealtime(3.0f);

//等待直到Func返回true,繼續(xù)執(zhí)行后續(xù)代碼

//yield return new WaitUntil(System.Func);

yield return new WaitUntil(() => true);

//等待直到Func返回false,繼續(xù)執(zhí)行后續(xù)代碼

//yield return new WaitWhile(System.Func);

yield return new WaitWhile(() => false);

//等待新開啟的協(xié)程完成后,繼續(xù)執(zhí)行后續(xù)代碼,可以利用這一點,實現(xiàn)遞歸

yield return StartCoroutine(Test());

//for循環(huán)

for (int i = 0; i < 10; i++)

Debug.Log(i);

yield return new WaitForSeconds(1);

//while循環(huán),while(true):如果循環(huán)體內(nèi)有yield return···語句,不會因為死循環(huán)卡死

int j = 0;

while (j < 10)

j++;

Debug.Log(j);

yield return new WaitForSeconds(1);

//終止本協(xié)程

yield break;

分享一位大大的翻譯博文,關(guān)于同步等待、同步協(xié)程、異步協(xié)程、并行協(xié)程,圖文說明非常清晰~

總結(jié)

以上是生活随笔為你收集整理的unity update 协程_Unity协程,停止协程及yield return使用_019的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。