public void RegisterHandler(MessageProcessUnitBase module, int noticeID, NotificationHandlerDelegate handler) { if (module != null && handler != null) { NotificationHandler notificationHandler = new NotificationHandler(noticeID, handler); CollectionUtil.AddIntoTable(noticeID, notificationHandler, notificationHandlerTable); CollectionUtil.AddIntoTable(module, noticeID, notificationHandler, moduleNotificationRegisterTable); #if UNITY_EDITOR if (LogUtil.ShowDebug != null) { LogUtil.ShowDebug(string.Format("[本地通知中心]1.注册通知处理器:来自[{0}] 通知ID[{1}] 处理回调[{2}]", module.GetType().Name, noticeID, StringUtility.ToString(handler))); } #endif } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("注册通知处理器时传递的参数有[null]值:通知ID[{0}] 模块[{1}] 处理回调[{2}]", noticeID, StringUtility.ToString(module), StringUtility.ToString(handler))); } } #endif }
public void ResumeAllHandlersBelongToModule(MessageProcessUnitBase module) { if (module != null) { if (moduleMessageRegisterTable != null) { Dictionary <Type, MessageHandler> handlerTable; if (moduleMessageRegisterTable.TryGetValue(module, out handlerTable)) { foreach (MessageHandler handler in handlerTable.Values) { handler.Activate(); } } } } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("恢复消息处理器时传递的参数有[null]值:模块[{0}]", StringUtility.ToString(module))); } } #endif }
public void DeliverNotificationExclude(int noticeID, MessageProcessUnitBase excludeTerminal) { if (excludeTerminal != null) { List <NotificationHandler> handlers; if (notificationHandlerTable.TryGetValue(noticeID, out handlers)) { NotificationHandler excludeHandler = CollectionUtil.GetFromTable(excludeTerminal, noticeID, moduleNotificationRegisterTable); for (int i = 0; i < handlers.Count; ++i) { if (handlers[i] != excludeHandler) { Invoke(handlers[i], noticeID); } } } } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("发送通知时传递的参数有[null]值:消息[{0}] 接收端[{1}]", noticeID, StringUtility.ToString(excludeTerminal))); } } #endif }
public void UnregisterAllHandlersBelongToModule(MessageProcessUnitBase module) { if (module != null) { Dictionary <int, NotificationHandler> handlerTable; if (moduleNotificationRegisterTable.TryGetValue(module, out handlerTable)) { foreach (NotificationHandler handler in handlerTable.Values) { List <NotificationHandler> tmpList; if (notificationHandlerTable.TryGetValue(handler.noticeID, out tmpList)) { tmpList.Remove(handler); #if UNITY_EDITOR if (LogUtil.ShowDebug != null) { LogUtil.ShowDebug(string.Format("[本地通知中心]2.注销通知处理器:来自[{0}] 通知ID[{1}] 处理回调[{2}]", module.GetType().Name, handler.noticeID, StringUtility.ToString(handler.Handler))); } #endif } } moduleNotificationRegisterTable.Remove(module); } } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("注销通知处理器时传递的参数有[null]值:模块[{0}]", StringUtility.ToString(module))); } } #endif }
public static void BroadcastExclude(int noticeID, MessageProcessUnitBase excludeTerminal) { try { NotificationCentralHub.Instance.DeliverNotification(noticeID, excludeTerminal, 投递选项.指定目标为排除对象); } catch (System.Exception ex) { Debug.LogException(ex); } }
public static void SendTo(int noticeID, MessageProcessUnitBase terminal) { try { currentNoticeID = noticeID; NotificationCentralHub.Instance.DeliverNotification(noticeID, terminal); } catch (System.Exception ex) { Debug.LogException(ex); } }
public void UnregisterAllHandlersBelongToModule(MessageProcessUnitBase module) { if (module != null) { if (moduleMessageRegisterTable != null) { Dictionary <Type, MessageHandler> handlerTable; if (moduleMessageRegisterTable.TryGetValue(module, out handlerTable)) { if (messageHandlerTable != null) { foreach (KeyValuePair <Type, MessageHandler> handlerKV in handlerTable) { if (!messageHandlerTableLocked) { CollectionUtil.RemoveFromTable(handlerKV.Key, handlerKV.Value, messageHandlerTable); #if UNITY_EDITOR if (LogUtil.ShowDebug != null) { LogUtil.ShowDebug(string.Format("[本地消息中心]2.注销消息处理器:来自[{0}] 消息类型[{1}] 处理回调[{2}]", module.GetType().Name, handlerKV.Key.Name, StringUtility.ToString(handlerKV.Value.Handler))); } #endif } else { RegisterModifier modifier = pool.Aquire(); modifier.isUnregister = true; modifier.messageType = handlerKV.Key; modifier.messageHandler = handlerKV.Value; modifier.module = module; if (messageHandlerRegisterChangeCache == null) { messageHandlerRegisterChangeCache = new List <RegisterModifier>(); } messageHandlerRegisterChangeCache.Add(modifier); } } } moduleMessageRegisterTable.Remove(module); } } } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("注销消息处理器时传递的参数有[null]值:模块[{0}]", StringUtility.ToString(module))); } } #endif }
private void InternalDeliverNotification(int noticeID, MessageProcessUnitBase terminal) { Dictionary <int, NotificationHandler> handlers; if (moduleNotificationRegisterTable.TryGetValue(terminal, out handlers)) { NotificationHandler handler; if (handlers.TryGetValue(noticeID, out handler)) { Invoke(handler, noticeID); } } }
public void DeliverNotification(int noticeID, MessageProcessUnitBase terminal, 投递选项 option) { switch (option) { case 投递选项.指定目标为投递对象: DeliverNotification(noticeID, terminal); break; case 投递选项.指定目标为排除对象: DeliverNotificationExclude(noticeID, terminal); break; } }
public void DeliverNotification(int noticeID, MessageProcessUnitBase terminal) { if (terminal != null) { InternalDeliverNotification(noticeID, terminal); } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("发送通知时传递的参数有[null]值:通知ID[{0}] 接收端[{1}]", noticeID, StringUtility.ToString(terminal))); } } #endif }
public void PauseAllHandlersBelongToModule(MessageProcessUnitBase module) { if (module != null) { Dictionary <int, NotificationHandler> handlerTable; if (moduleNotificationRegisterTable.TryGetValue(module, out handlerTable)) { foreach (NotificationHandler handler in handlerTable.Values) { handler.Deactivate(); } } } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("暂停通知处理器时传递的参数有[null]值:模块[{0}]", StringUtility.ToString(module))); } } #endif }
public void RegisterHandler(MessageProcessUnitBase module, MessageHandlerDelegate handler, Type msgType) { if (!typeof(IMessage).IsAssignableFrom(msgType)) { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("消息结构体[{0}]没有实现IMessage接口", msgType.Name)); } return; } #endif #if UNITY_EDITOR if (!msgType.IsValueType) { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("消息结构体[{0}]必须定义为值类型(struct)", msgType.Name)); } return; } object[] fieldsDefined = msgType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (fieldsDefined.Length <= 0) { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("消息结构体[{0}]中没有定义任何成员,如果不需要向外通知任何参数的话,使用Notification", msgType.Name)); } return; } #endif if (module != null && handler != null) { MessageHandler messageHandler = new MessageHandler(msgType, handler); if (!messageHandlerTableLocked) { if (messageHandlerTable == null) { messageHandlerTable = new Dictionary <Type, List <MessageHandler> >(); } CollectionUtil.AddIntoTable(msgType, messageHandler, messageHandlerTable); #if UNITY_EDITOR if (LogUtil.ShowDebug != null) { LogUtil.ShowDebug(string.Format("[本地消息中心]1.注册消息处理器:来自[{0}] 消息类型[{1}] 处理回调[{2}]", module.GetType().Name, msgType.Name, StringUtility.ToString(handler))); } #endif } else { RegisterModifier modifier = pool.Aquire(); modifier.isUnregister = false; modifier.messageType = msgType; modifier.messageHandler = messageHandler; modifier.module = module; if (messageHandlerRegisterChangeCache == null) { messageHandlerRegisterChangeCache = new List <RegisterModifier>(); } messageHandlerRegisterChangeCache.Add(modifier); } if (moduleMessageRegisterTable == null) { moduleMessageRegisterTable = new Dictionary <MessageProcessUnitBase, Dictionary <Type, MessageHandler> >(); } CollectionUtil.AddIntoTable(module, msgType, messageHandler, moduleMessageRegisterTable); } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("注册消息处理器时传递的参数有[null]值:消息类型[{0}] 模块[{1}] 处理回调[{2}]", msgType.Name, StringUtility.ToString(module), StringUtility.ToString(handler))); } } #endif }
public void RegisterHandler <T>(MessageProcessUnitBase module, MessageHandlerDelegate <T> handler) where T : IMessage { Type msgType = typeof(T);