Example #1
0
        public void SendMessage(string target, string msg, params object[] args)
        {
            BusinessModule module = GetModule(target);

            if (module != null)
            {
                module.HandleMessage(msg, args);
            }
        }
Example #2
0
        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);
        }
Example #3
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 = GetPreEventTable(target);
                evt = table.GetEvent(type);
                // this.LogWarning("Event() target不存在!将预监听事件! target:{0}, event:{1}", target, type);
            }
            return(evt);
        }