/// <summary> /// 分发事件 /// </summary> /// <param name="evt"></param>分发的消息名称 /// <param name="eventType"></param>消息事件类型 public void DispatchEvent(string evt, EventType eventType = EventType.UIMsg) { GameEvent gameEvent = new GameEvent(); gameEvent.EventType = eventType; EventData eventData = new EventData(); eventData.Cmd = evt; eventData.ParaList = null; gameEvent.Para = eventData; this.DispatchEvent(gameEvent); }
/// <summary> /// 内部实际调用的注册监听的方法 /// </summary> /// <param name="type"></param>要监听的事件类型 /// <param name="handler"></param>监听者(处理回调) private void RegisterHandler(EventType type, IEventHandler handler) { if (null != handler) { if (!handlerDic.ContainsKey((int)type)) { handlerDic.Add((int)type, new List <IEventHandler>()); } if (!handlerDic[(int)type].Contains(handler)) { handlerDic[(int)type].Add(handler); } } }
/// <summary> /// 分发事件 /// </summary> /// <param name="evt"></param>分发的消息名称 /// <param name="eventType"></param>消息事件类型 /// <param name="para"></param>参数 public void DispatchEvent(string evt, EventType eventType = EventType.UIMsg, params object[] para) { GameEvent gameEvent = new GameEvent(); gameEvent.EventType = eventType; EventData eventData = new EventData(); eventData.Cmd = evt; if (null != para) { eventData.ParaList = new List <object>(); for (int i = 0; i < para.Length; i++) { eventData.ParaList.Add(para[i]); } } gameEvent.Para = eventData; this.DispatchEvent(gameEvent); }