private void SendMessage_Internal(bool isCall, string target, string msg, object[] args) { BusinessModule module = GetModule(target); if (module != null) { if (isCall) { module.CallMethod(msg, args); } else { module.HandleMessage(msg, args); } } else { List <MessageObject> list = GetCacheMessageList(target); MessageObject obj = new MessageObject(); obj.target = target; obj.msg = msg; obj.args = args; obj.isCall = isCall; list.Add(obj); } }
/// <summary> /// 通过反射创建业务模块 /// </summary> public BusinessModule CreateModule(string name, object arg = null) { if (m_mapModules.ContainsKey(name)) { LogMgr.LogWarning("The Module<{0}> Has Existed!", name); return(null); } BusinessModule module = null; Type type = Type.GetType(m_domain + "." + name); if (type != null) { module = Activator.CreateInstance(type) as BusinessModule; } else { module = new LuaModule(name); LogMgr.LogWarning("The Module<{0}> Is LuaModule!", name); } m_mapModules.Add(name, module); //处理预监听的事件 EventTable eventTable = null; if (m_mapPreListenEvents.ContainsKey(name)) { eventTable = m_mapPreListenEvents[name]; m_mapPreListenEvents.Remove(name); } module.SetEventTable(eventTable); module.Create(arg); //处理缓存的消息 if (m_mapCacheMessage.ContainsKey(name)) { List <MessageObject> messageList = m_mapCacheMessage[name]; foreach (MessageObject item in messageList) { if (item.isCall) { module.CallMethod(item.msg, item.args); } else { module.HandleMessage(item.msg, item.args); } } m_mapCacheMessage.Remove(name); } return(module); }
public void ReleaseModule(BusinessModule module) { if (module != null) { if (m_mapModules.ContainsKey(module.Name)) { LogMgr.Log("ReleaseModule name = {0}", module.Name); m_mapModules.Remove(module.Name); module.Release(); } else { LogMgr.LogError("模块不是由ModuleManager创建的! name = {0}", module.Name); } } else { LogMgr.LogError("module = null!"); } }