unity3d:ugui双击按钮
立羽
发布
于
2023-08-24 14:33:46
发布
于
2023-08-24 14:33:46
public class ClickEventListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
public static ClickEventListener Get(GameObject obj)
ClickEventListener listener = obj.GetComponent<ClickEventListener>();
if (listener == null)
listener = obj.AddComponent<ClickEventListener>();
return listener;
System.Action<GameObject> mClickedHandler = null;
System.Action<GameObject> mDoubleClickedHandler = null;
System.Action<GameObject> mOnPointerDownHandler = null;
System.Action<GameObject> mOnPointerUpHandler = null;
bool mIsPressed = false;
public bool IsPressd
get { return mIsPressed; }
public void OnPointerClick(PointerEventData eventData)
if (eventData.clickCount == 2)
if (mDoubleClickedHandler != null)
mDoubleClickedHandler(gameObject);
if (mClickedHandler != null)
mClickedHandler(gameObject);
public void SetClickEventHandler(System.Action<GameObject> handler)
mClickedHandler = handler;
public void SetDoubleClickEventHandler(System.Action<GameObject> handler)
mDoubleClickedHandler = handler;
public void SetPointerDownHandler(System.Action<GameObject> handler)
mOnPointerDownHandler = handler;
public void SetPointerUpHandler(System.Action<GameObject> handler)
mOnPointerUpHandler = handler;
public void OnPointerDown(PointerEventData eventData)
mIsPressed = true;
if (mOnPointerDownHandler != null)
mOnPointerDownHandler(gameObject);
public void OnPointerUp(PointerEventData eventData)
mIsPressed = false;
if (mOnPointerUpHandler != null)