Ejemplo n.º 1
0
 protected EventTable GetEventTable()
 {
     if (m_tblEvent == null)
     {
         m_tblEvent = new EventTable();
     }
     return(m_tblEvent);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 这里应该去加载Lua脚本
        /// 并且将EventManager映射到Lua脚本中
        /// </summary>
        /// <param name="args"></param>
        public override void Create(object args = null)
        {
            base.Create(args);
            this.Log("Create() Lua = " + Name);
            m_args = args;

            EventTable mgrEvent = GetEventTable();
            //TODO 需要映射到Lua脚本中
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 调用它以释放模块
        /// </summary>
        public override void Release()
        {
            if (m_tblEvent != null)
            {
                m_tblEvent.Clear();
                m_tblEvent = null;
            }

            base.Release();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 通过名字创建一个业务模块
        /// 先通过名字反射出Class,如果不存在
        /// 则通过扫描Lua文件目录加载LuaModule
        /// </summary>
        /// <param name="name">业务模块的名字</param>
        /// <param name="args"></param>
        /// <returns></returns>
        public BusinessModule CreateModule(string name, object args = null)
        {
            this.Log("CreateModule() name = " + name + ", args = " + args);

            if (m_mapModules.ContainsKey(name))
            {
                this.LogError("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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <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);
                this.LogWarning("Event() target不存在!将预监听事件! target:{0}, event:{1}", target, type);
            }
            return(evt);
        }
Ejemplo n.º 7
0
        //=======================================================
        public ModuleEvent Event(string target, string type)
        {
            ModuleEvent evt = null;

            BusinessModule module = GetModule(target);

            if (module != null)
            {
                evt = module.Event(type);
            }
            else
            {
                EventTable table = GetPreListenEventTable(target);
                evt = table.GetEvent(type);
            }

            return(evt);
        }
Ejemplo n.º 8
0
 internal void SetEventTable(EventTable mgrEvent)
 {
     m_tblEvent = mgrEvent;
 }
Ejemplo n.º 9
0
 //===============================================
 internal void SetEventTable(EventTable tblEvent)
 {
     m_tblEvent = tblEvent;
 }