public static class UIUltil { public static void RigistEventTrigger(this UIBehaviour _ui, EventTriggerType _eventTriggerType, Action<PointerEventData> _callback) { if (_ui == null) { Debug.LogError("invalid UIBehaviour can not be a trigger content."); return; } else { EventTrigger eventTrigger = _ui.GetComponent<EventTrigger>(); if (eventTrigger == null) { eventTrigger = _ui.gameObject.AddComponent<EventTrigger>(); } EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = _eventTriggerType; entry.callback.AddListener((_pointData) => { var baseData = _pointData as PointerEventData; _callback?.Invoke(baseData); }); eventTrigger.triggers.Add(entry); } } public static void RigistEventTrigger(this UIBehaviour _ui, EventTriggerType _eventTriggerType, Action _callback) { if (_ui == null) { Debug.LogError("invalid UIBehaviour can not be a trigger content."); return; } else { EventTrigger eventTrigger = _ui.GetComponent<EventTrigger>(); if (eventTrigger == null) { eventTrigger = _ui.gameObject.AddComponent<EventTrigger>(); } EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = _eventTriggerType; entry.callback.AddListener((_pointData) => { //var baseData = _pointData as PointerEventData; _callback?.Invoke(); }); eventTrigger.triggers.Add(entry); } } }
标签:EventTrigger,eventTrigger,callback,Unity,添加,ui,entry,null From: https://www.cnblogs.com/WantPeach/p/18231240