C#委托

时间:2016-10-16 00:48:10   收藏:0   阅读:194
public class myButtonEvent : MonoBehaviour {
    delegate void Proxy();

    // Use this for initialization
    void Start () {
        Debug.Log ("myButtonEvent---start");
        Proxy pxy = OnMyClick; //可以直接赋值,其实就是函数指针
        pxy += OnMyClick; //可以这样加
        pxy += new Proxy (OnMyClick);//也可以这样加
        pxy (); //调用
        Button blt = GetComponent<Button> ();

        //blt.onClick += pxy; //onclick并不是一个委托,是一个普通类
        blt.onClick.AddListener (OnMyClick);

    }
    
    // Update is called once per frame
    void Update () {
    
    }

    public void bltClick(){
        Debug.Log ("bltclick");
    }

    public void OnMyClick(){
        Debug.Log ("OnMyClick()");
    }
}

 

原文:http://www.cnblogs.com/timeObjserver/p/5965537.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!