zoukankan      html  css  js  c++  java
  • Unity3d 协程、调用函数、委托

    (一)协程

    开启方法: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 initialization
    	void 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 initialization
    	void 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 initialization
    	void Start () {
            //创建委托对象
            TestEntrust rl = new TestEntrust(ReceiveLogic);
            //调用
            rl(3);
           }
    }





  • 相关阅读:
    java解析php函数json_encode unicode 编码问题
    python根据域名循环遍历查找绑定IP
    android开发 sqlite设置本地时间
    android判断指定软件是否安装
    android中安装,启动和卸载应用
    .net程序员面试题
    error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
    jQuery EasyUI学习笔记
    [转载]NetBox使用教程!
    Sql一次清空所有数据(基于 Mgo Bcp)
  • 原文地址:https://www.cnblogs.com/lexiaoyao-jun/p/5208253.html
Copyright © 2011-2022 走看看