Unity EventTriggerListener.cs 点击事件
using UnityEngine; using UnityEngine.EventSystems; public class EventTriggerListener:EventTrigger { public delegate void VoidDelegate(GameObject go); public delegate void VectorDelegate(GameObject go, Vector2 delta); public VoidDelegate onClick; public VoidDelegate onDown; public VoidDelegate onEnter; public VoidDelegate onExit; public VoidDelegate onUp; public VoidDelegate onSelect; public VoidDelegate onUpdateSelect; public VectorDelegate onDrag; public VoidDelegate onDragOut; public static EventTriggerListener Get(GameObject go) { if (go == null) { Debug.LogError("EventTriggerListener_go_is_NULL"); return null; } else { EventTriggerListener listener = go.GetComponent<EventTriggerListener>(); if (listener == null) listener = go.AddComponent<EventTriggerListener>(); return listener; } } public override void OnDrag(PointerEventData eventData) { onDrag?.Invoke(gameObject, eventData.delta); } public override void OnEndDrag(PointerEventData eventData) { onDragOut?.Invoke(gameObject); } public override void OnPointerClick(PointerEventData eventData) { onClick?.Invoke(gameObject); } public override void OnPointerDown(PointerEventData eventData) { onDown?.Invoke(gameObject); } public override void OnPointerEnter(PointerEventData eventData) { onEnter?.Invoke(gameObject); } public override void OnPointerExit(PointerEventData eventData) { onExit?.Invoke(gameObject); } public override void OnPointerUp(PointerEventData eventData) { onUp?.Invoke(gameObject); } public override void OnSelect(BaseEventData eventData) { onSelect?.Invoke(gameObject); } public override void OnUpdateSelected(BaseEventData eventData) { onUpdateSelect?.Invoke(gameObject); } }
posted on 2021-12-20 10:15 zqiang0803 阅读(81) 评论(0) 编辑 收藏 举报