首页 > 编程语言 > 详细

Unity3D-c#委托与事件

时间:2015-06-27 11:30:34      阅读:225      评论:0      收藏:0      [点我收藏+]

 先定义一个委托,然后定义一个委托类型的事件,最后向该事件中注册有委托格式的方法。

eg:

1.先定义委托

   

public delegate void ButtonUpHandler(string buttonName);//参数类型为string,返回值为Void

2.定义委托类型的事件

  

public static event ButtonDownHandler On_ButtonDown;//类型为ButtonDownHandler 的事件

3.向该事件中注册有委托格式(

参数类型为string,返回值为Void

)的方法

  void Start () {
        EasyButton .On_ButtonDown += DownMethod;//向事件On_ButtonDown中注册具有委托格式的方法
    }
    

    void DownMethod(string btnName)//具有委托格式的方法
    {
        print ("Down!");
    }

 

Unity3D-c#委托与事件

原文:http://www.cnblogs.com/tengjinchao/p/4603748.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!