Example #1
0
        public GeneralModule GetModule(string name)
        {
            GeneralModule module = null;

            m_mapModules.TryGetValue(name, out module);
            return(module);
        }
Example #2
0
        //============================================================================
        //消息机制
        //============================================================================

        public void SendMessage(string target, string msg, params object[] args)
        {
            GeneralModule module = GetModule(target);

            if (module != null)
            {
                module.HandleMessage(msg, args);
            }
            else
            {
                var           list = GetCacheMessageList(target);
                MessageObject obj  = new MessageObject();
                obj.msg  = msg;
                obj.args = args;
                list.Add(obj);
            }
        }
Example #3
0
        public GeneralModule CreateModule(string name, object args = null)
        {
            Debuger.Log("name = " + name + ", args = " + args);

            if (HasModule(name))
            {
                Debuger.LogError("The Module<{0}> Has Existed!");
                return(null);
            }

            GeneralModule module = null;

            for (int i = 0; i < m_listModuleActivators.Count; i++)
            {
                module = m_listModuleActivators[i].CreateInstance(name);
                if (module != null)
                {
                    break;
                }
            }


            if (module == null)
            {
                Debuger.LogError("模块实例化失败!");
                return(null);
            }

            m_mapModules.Add(name, module);
            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);
        }