Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public GeneralModule CreateModule(string name, object args = null)
        {
            Debug.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);
        }