UGUI 之 控件以及按钮的监听事件系统 存档

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class UIMain : MonoBehaviour {
        Button        button;
        Image image;
        void Start ()
        {
                button = transform.Find("Button").GetComponent<Button>();
                image = transform.Find("Image").GetComponent<Image>();
                EventTriggerListener.Get(button.gameObject).onClick =OnButtonClick;
                EventTriggerListener.Get(image.gameObject).onClick =OnButtonClick;
        }
  
        private void OnButtonClick(GameObject go){
                //在这里监听按钮的点击事件
                if(go == button.gameObject){
                        Debug.Log ("DoSomeThings");
                }
        }
}
posted on 2015-06-18 10:17  橙小风  阅读(191)  评论(0编辑  收藏  举报