码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D-c#委托与事件

时间:2015-06-27 11:33:07      阅读:179      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!