使用OnPointerXXX有两种方式,一种是实现IPointerXXXHandler接口,另一种就是利用EventTrigger添加回调事件。如下:
EventTrigger trigger = compareBtn.GetComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) =>
{
OnPointerDownDelegate((PointerEventData)data);
});
trigger.triggers.Add(entry);
EventTrigger.Entry entry2 = new EventTrigger.Entry();
entry2.eventID = EventTriggerType.PointerUp;
entry2.callback.AddListener((data) =>
{
OnPointerUpDelegate((PointerEventData)data);
});
trigger.triggers.Add(entry2);
网友评论