挂载到对象即可,然后注册回调做down和up的处理
using UnityEngine;
using UnityEngine.EventSystems;
public class PushListener : MonoBehaviour,IPointerDownHandler, IPointerUpHandler
{
public delegate void VoidDelegate(Transform obj, object param);
public VoidDelegate DownCall = null;
public object DownParam = null;
public VoidDelegate UpCall = null;
public object UpParam = null;
public void OnPointerDown(PointerEventData data)
{
if (DownCall != null)
{
DownCall(transform, DownParam);
}
}
public void OnPointerUp(PointerEventData data)
{
if (UpCall != null)
{
UpCall(transform, UpParam);
}
}
public void SetDown(VoidDelegate call, object param)
{
DownCall = call;
DownParam = param;
}
public void SetUp(VoidDelegate call, object param)
{
UpCall = call;
UpParam = param;
}
}