UGUI按钮事件管理

作者: Babybus_Unity | 来源:发表于2015-12-17 12:00 被阅读237次
    using UnityEngine;
    using System.Collections;
    using UnityEngine.Events;
    using UnityEngine.EventSystems;
    public class EventTriggerListener : UnityEngine.EventSystems.EventTrigger {
        public UnityAction<GameObject,PointerEventData> onClick;
        public UnityAction<GameObject,PointerEventData> onDown;
        public UnityAction<GameObject,PointerEventData> onEnter;
        public UnityAction<GameObject,PointerEventData> onExit;
        public UnityAction<GameObject,PointerEventData> onUp;
        public UnityAction<GameObject,BaseEventData> onSelect;
        public UnityAction<GameObject,BaseEventData> onUpdateSelect;
        static public EventTriggerListener Get(GameObject go)
        {
            EventTriggerListener listener = go.GetComponent<EventTriggerListener>();
            if (listener == null) listener = go.AddComponent<EventTriggerListener>();
            return listener;
        }
        public override void OnPointerClick(PointerEventData eventData)
        {
            if (onClick != null) onClick(gameObject, eventData);
        }
        public override void OnPointerDown(PointerEventData eventData)
        {
            if (onDown != null) onDown(gameObject,eventData);
        }
        public override void OnPointerEnter(PointerEventData eventData)
        {
            if (onEnter != null) onEnter(gameObject,eventData);
        }
        public override void OnPointerExit(PointerEventData eventData)
        {
            if (onExit != null) onExit(gameObject,eventData);
        }
        public override void OnPointerUp(PointerEventData eventData)
        {
            if (onUp != null) onUp(gameObject,eventData);
        }
        public override void OnSelect(BaseEventData eventData)
        {
            if (onSelect != null) onSelect(gameObject,eventData);
        }
        public override void OnUpdateSelected(BaseEventData eventData)
        {
            if (onUpdateSelect != null) onUpdateSelect(gameObject,eventData);
        }
    }
    

    相关文章

      网友评论

        本文标题:UGUI按钮事件管理

        本文链接:https://www.haomeiwen.com/subject/jqlphttx.html