日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity3d 协程、调用函数、委托

發布時間:2025/5/22 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity3d 协程、调用函数、委托 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

(一)協程

開啟方法:StartCoroutine("函數名");

結束方法StopCoroutine("函數名"),StopAllCoroutines();

IEnumerator?TestIEnumerator(){Debug.Log("協程");//等待游戲界面繪制完成yield?return?new?WaitForEndOfFrame();Debug.Log("游戲界面繪制完成");//等待1秒后yield?return?new?WaitForSeconds(1F);Debug.Log("1秒后");//等待0.5秒后yield?return?new?WaitForSeconds(0.5F);Debug.Log("0.5秒后");while(true){//等待固定更新yield?return?new?WaitForFixedUpdate();Debug.Log("固定更新");}}//?Use?this?for?initializationvoid?Start?()?{StartCoroutine("TestIEnumerator");}




(二)調用函數

開啟方法 不重復調用 Invoke("函數名",“延遲時間”); 重復調用 InvokeRepeating("函數名",“延遲時間”,“重復間隔時間”);

結束方法 CancelInvoke("函數名"),CancelInvoke();

是否在有在調用的函數 IsInvoking(); 指定函數是否在調用 IsInvoking("函數名");

void?TestInvokeRepeating(){Debug.Log("重復調用");m_round++;if?(m_round?>?15){//結束所有調用//CancelInvoke();//結束指定調用CancelInvoke("TestInvokeRepeating");}if?(IsInvoking("TestInvokeRepeating")){Debug.Log("調用中");}else{Debug.Log("不在調用中");}}void?TestInvokeRepeating2(){Debug.Log("重復調用TestInvokeRepeating2");}//?Use?this?for?initializationvoid?Start?()?{m_round?=?0;InvokeRepeating("TestInvokeRepeating",0f,1f);InvokeRepeating("TestInvokeRepeating2",?0f,?1f); }



(二)委托

public?class?GameManager?:?MonoBehaviour {//定義一個委托delegate?int?TestEntrust(int?a);public?int?ReceiveLogic(int?a){Debug.Log("參數a="+a);return?0;}//?Use?this?for?initializationvoid?Start?()?{//創建委托對象TestEntrust?rl?=?new?TestEntrust(ReceiveLogic);//調用rl(3);} }






轉載于:https://my.oschina.net/igames/blog/618982

總結

以上是生活随笔為你收集整理的Unity3d 协程、调用函数、委托的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。