/************************************************************************************************** Copyright (C) 2021 - All Rights Reserved. -------------------------------------------------------------------------------------------------------- 当前版本:1.0; 文 件 : MessageDispatcher.cs; 作 者 : HuBingJie; 时 间 : 2021 - 06 - 22; 注 释 : 消息中心,方便各系统之间通信; **************************************************************************************************/ using System.Collections.Generic; public delegate void MessageHandler(uint iMessageType, object arg); public class MessageDispatcher : DataSingleton { Dictionary m_HandlerMap; public MessageDispatcher() { m_HandlerMap = new Dictionary(); } public MessageHandler RegisterMessageHandler(uint iMessageType, MessageHandler handler) { if (handler == null) return null; if (!m_HandlerMap.ContainsKey(iMessageType)) { MessageHandler Handlers = handler; m_HandlerMap.Add(iMessageType, Handlers); } else { m_HandlerMap[iMessageType] += handler; } return handler; } public void UnRegisterMessageHandler(uint iMessageType, MessageHandler handler) { if (handler == null) return; if (m_HandlerMap.ContainsKey(iMessageType)) { m_HandlerMap[iMessageType] -= handler; } } public void SendMessage(uint iMessageType, object arg) { if (m_HandlerMap.ContainsKey(iMessageType)) { if (m_HandlerMap[iMessageType] != null) { m_HandlerMap[iMessageType].Invoke(iMessageType, arg); } } } public override void Init() { } public override void OnDispose() { throw new System.NotImplementedException(); } }