/// <summary> /// 清空指定事件的所有监听 /// </summary> /// <param name="type"></param> public void Clear(E_Event_Type type) { if (eventDic.ContainsKey(type)) { eventDic.Remove(type); } }
/// <summary> /// 移除事件监听 /// </summary> /// <param name="type"></param> /// <param name="fun"></param> public void RemoveEventListener(E_Event_Type type, UnityAction fun) { if (eventDic.ContainsKey(type)) { (eventDic[type] as EventInfo).action -= fun; } }
/// <summary> /// 触发事件 /// </summary> /// <param name="type"></param> /// <param name="info"></param> public void EventTrigger(E_Event_Type type) { if (eventDic.ContainsKey(type)) { if ((eventDic[type] as EventInfo).action != null) { (eventDic[type] as EventInfo).action(); } } }
/// <summary> /// 触发事件 /// </summary> /// <param name="type"></param> /// <param name="info"></param> public void EventTrigger <T>(E_Event_Type type, T info) { if (eventDic.ContainsKey(type)) { if ((eventDic[type] as EventInfo <T>).action != null) { (eventDic[type] as EventInfo <T>).action(info); } } }
/// <summary> /// 添加事件监听 /// </summary> /// <param name="type"></param> /// <param name="fun"></param> //public void AddEventListener( E_Event_Type type, UnityAction<object> fun ) public void AddEventListener(E_Event_Type type, UnityAction fun) { if (eventDic.ContainsKey(type)) { (eventDic[type] as EventInfo).action += fun; } else { eventDic.Add(type, new EventInfo(fun)); } }
/// <summary> /// 添加事件监听 /// </summary> /// <param name="type"></param> /// <param name="fun"></param> //public void AddEventListener( E_Event_Type type, UnityAction<object> fun ) public void AddEventListener <T>(E_Event_Type type, UnityAction <T> fun) { //if (eventDic.ContainsKey(type)) // eventDic[type] += fun; //else // eventDic.Add(type, fun); if (eventDic.ContainsKey(type)) { (eventDic[type] as EventInfo <T>).action += fun; } else { eventDic.Add(type, new EventInfo <T>(fun)); } }