自己写一个类来添加事件鼠标左边按钮事件监听

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System.Collections;

namespace UIWidgets {
    /// 
    /// OnClick listener.
    /// 
    [AddComponentMenu("UI/UIWidgets/AccordionItemComponent")]
    public class AccordionItemComponent : MonoBehaviour, IPointerClickHandler, ISubmitHandler {

        /// 
        /// What to do when the event system send a pointer click event.
        /// 
        public UnityEvent OnClick = new UnityEvent();

        /// 
        /// Raises the pointer click event.
        /// 
        /// Event data.
        public virtual void OnPointerClick(PointerEventData eventData)
        {
            if (eventData.button!=PointerEventData.InputButton.Left)
            {
                return;
            }

            OnClick.Invoke();
        }

        /// 
        /// Raises the submit event.
        /// 
        /// Event data.
        public virtual void OnSubmit(BaseEventData eventData)
        {
            OnClick.Invoke();
        }
    }
}

 

你可能感兴趣的:(自己写一个类来添加事件鼠标左边按钮事件监听)