Beispiel #1
0
 protected EventTable GetEventTable()
 {
     if (m_tblEvent == null)
     {
         m_tblEvent = new EventTable();
     }
     return(m_tblEvent);
 }
        private EventTable GetPreEventTable(string target)
        {
            EventTable table = null;

            if (!_preListenEventDic.TryGetValue(target, out table))
            {
                table = new EventTable();
                _preListenEventDic.Add(target, table);
            }
            return(table);
        }
        public BusinessModule CreateBusinessModule(string name, object args = null)
        {
            this.Log("CreateModule() name = " + name + ", args = " + args);

            if (_businessModuleDic.ContainsKey(name))
            {
                this.Log(Debuger.DebugColor.Red, "CreateModule() The Module<{0}> Has Existed!");
                return(null);
            }

            BusinessModule module = null;
            Type           type   = Type.GetType(_domain + "." + name);

            if (type != null)
            {
                module = Activator.CreateInstance(type) as BusinessModule;
            }
            else
            {
                // module = new LuaModule(name);
            }
            _businessModuleDic.Add(name, module);

            //处理预监听的事件
            if (_preListenEventDic.ContainsKey(name))
            {
                EventTable mgrEvent = null;
                mgrEvent = _preListenEventDic[name];
                _preListenEventDic.Remove(name);

                module.SetEventTable(mgrEvent);
            }

            module.Create(args);

            //处理缓存的消息
            if (_messageCacheDic.ContainsKey(name))
            {
                List <MessageObj> list = _messageCacheDic[name];
                for (int i = 0; i < list.Count; i++)
                {
                    MessageObj msgobj = list[i];
                    module.HandleMessage(msgobj.msg, msgobj.args);
                }
                _messageCacheDic.Remove(name);
            }

            return(module);
        }
        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);
        }
Beispiel #5
0
 internal void SetEventTable(EventTable mgrEvent)
 {
     m_tblEvent = mgrEvent;
 }