protected EventTable GetEventTable() { if (m_tblEvent == null) { m_tblEvent = new EventTable(); } return(m_tblEvent); }
/// <summary> /// 调用它以释放模块 /// </summary> public override void Release() { if (m_tblEvent != null) { m_tblEvent.Clear(); m_tblEvent = null; } base.Release(); }
private EventTable GetPreEventTable(string target) { EventTable table = null; if (!m_mapPreListenEvents.ContainsKey(target)) { table = new EventTable(); m_mapPreListenEvents.Add(target, table); } else { table = m_mapPreListenEvents[target]; } return(table); }
/// <summary> /// 通过名字创建一个业务模块 /// 先通过名字反射出Class,如果不存在 /// 则通过扫描Lua文件目录加载LuaModule /// </summary> /// <param name="name">业务模块的名字</param> /// <param name="args"></param> /// <returns></returns> public BusinessModule CreateModule(string name, object args = null) { if (m_mapModules.ContainsKey(name)) { Log.Error("CreateModule() The Module<{0}> Has Existed!"); 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); } m_mapModules.Add(name, module); //处理预监听的事件 if (m_mapPreListenEvents.ContainsKey(name)) { EventTable mgrEvent = null; mgrEvent = m_mapPreListenEvents[name]; m_mapPreListenEvents.Remove(name); module.SetEventTable(mgrEvent); } module.Create(args); //处理缓存的消息 if (m_mapCacheMessage.ContainsKey(name)) { List <MessageObject> list = m_mapCacheMessage[name]; for (int i = 0; i < list.Count; i++) { MessageObject msgobj = list[i]; module.HandleMessage(msgobj.msg, msgobj.args); } m_mapCacheMessage.Remove(name); } return(module); }
/// <summary> /// 监听指定模块的指定事件 /// </summary> /// <param name="target"></param> /// <param name="type"></param> /// <returns></returns> public ModuleEvent Event(string target, string type) { ModuleEvent evt = null; BusinessModule module = GetModule(target); if (module != null) { evt = module.Event(type); } else { //预创建事件 EventTable table = GetPreEventTable(target); evt = table.GetEvent(type); Log.Warning("Event() target不存在!将预监听事件! target:{0}, event:{1}", target, type); } return(evt); }
internal void SetEventTable(EventTable mgrEvent) { m_tblEvent = mgrEvent; }