using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ProjectBase.Event { public class EventHandlerItem { public string eventKey; public List eventInfos = new List(); public EventHandler action; public EventHandlerItem(string key, EventHandler handler, int time) { eventKey = key; eventInfos.Add(new EventInfo(handler, time)); action += handler; } /// /// 添加事件 /// /// 事件 /// 次数 public void AddEventHandler(EventHandler handler, int time) { eventInfos.Add(new EventInfo(handler, time)); action += handler; } /// /// 触发事件 /// /// 参数 public void EventHandlerTrigger(BaseEventData eventData) { action?.Invoke(eventData); for (int i = eventInfos.Count - 1; i >= 0; i--) { if (eventInfos[i].time == EventCenter.Infinity) { continue; } eventInfos[i].time--; if (eventInfos[i].time <= 0) { eventInfos.Remove(eventInfos[i]); action -= eventInfos[i].action; } } } public void RemoveEventHandler(EventHandler handler) { for (int i = eventInfos.Count - 1; i >= 0; i--) { if (eventInfos[i].action == handler) { eventInfos.Remove(eventInfos[i]); action -= handler; } } } } }