Пример #1
0
 /// <summary>
 /// 事件表
 /// </summary>
 /// <returns></returns>
 protected EventTable GetEventTable()
 {
     if (m_tblEvent == null)
     {
         m_tblEvent = new EventTable();
     }
     return(m_tblEvent);
 }
Пример #2
0
 public override void Release()
 {
     if (m_mtbEvent != null)
     {
         m_mtbEvent.Clear();
         m_mtbEvent = null;
     }
 }
Пример #3
0
 /// <summary>
 /// 清空模块事件
 /// </summary>
 public override void Release()
 {
     if (m_tblEvent != null)
     {
         m_tblEvent.Clear(); //清空事件表
         m_tblEvent = null;
     }
     base.Release();
 }
Пример #4
0
        public BusinessModule CreateModule(string name, object args = null)
        {
            if (m_mapModules.ContainsKey(name))
            {
                return(null);
            }

            BusinessModule module = null;

            Type type = Type.GetType(m_domain + "." + name);

            if (type != null)
            {
                Debug.Log(name + "   has created");
                module = Activator.CreateInstance(type) as BusinessModule;
            }

            else
            {
                module = new LuaModule(name);
            }

            m_mapModules.Add(name, module);

            //处理预监听事件
            if (m_mapPreListenEvents.ContainsKey(name))
            {
                EventTable tblEvent = m_mapPreListenEvents[name];
                m_mapPreListenEvents.Remove(name);

                module.SetEventTable(tblEvent);
            }

            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);
        }
        private EventTable GetPreListenEventTable(string target)
        {
            EventTable table = null;

            if (m_mapPreListenEvents.ContainsKey(target))
            {
                table = m_mapPreListenEvents[target];
            }
            else
            {
                table = new EventTable();
                m_mapPreListenEvents.Add(target, table);
            }
            return(table);
        }
Пример #6
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 = GetPreListEventTable(target);
                evt = table.GetEvent(type);
            }
            return(evt);
        }
        /// <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 = GetPreListenEventTable(target);
                evt = table.GetEvent(type);
            }
            return(evt);
        }
        /// <summary>
        /// 创建模块
        /// </summary>
        /// <param name="name">模块类名</param>
        /// <param name="args">参数可为空</param>
        /// <returns></returns>
        public BusinessModule CreateModule(string name, object args = null)
        {
            if (m_mapModule.ContainsKey(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); //不存在可能是lua模块
            }
            m_mapModule.Add(name, module);    //添加进管理器
            //处理预监听的事件
            if (m_mapPreListenEvents.ContainsKey(name))
            {
                EventTable tblEvent = m_mapPreListenEvents[name];
                m_mapPreListenEvents.Remove(name); //取出这个预监听事件
                module.SetEventTable(tblEvent);    //设置给这个模块
            }
            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);
        }
Пример #9
0
 internal void SetEventTable(EventTable tblEvent)
 {
     m_tblEvent = tblEvent;
 }
Пример #10
0
 internal void SetEventTable(EventTable table)
 {
     m_mtbEvent = table;
 }