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);
}
}
网友评论