/// <summary>
        /// 查找模块
        /// </summary>
        /// <param name="type">模块类型</param>
        /// <param name="name">模块名称</param>
        /// <returns></returns>
        public FrameworkModule FindModule(Type type, string name = "")
        {
            if (string.IsNullOrEmpty(name))
            {
                name = string.Format("{0}.{1}", _chunck, type.Name);
            }
            FrameworkModule mou = default(FrameworkModule);

            if (moudle_dic.ContainsKey(type))
            {
                mou = moudle_dic[type].Find((m) => { return(m.name == name); });
            }
            if (mou == null)
            {
                if (onModuleNotExist != null)
                {
                    onModuleNotExist(type, name);
                    if (moudle_dic.ContainsKey(type))
                    {
                        mou = moudle_dic[type].Find((m) => { return(m.name == name); });
                    }
                }
            }
            return(mou);
        }
        /// <summary>
        /// 创建一个模块,创建完了自动绑定
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public FrameworkModule CreateModule(Type type, string name = "")
        {
            var mou = FrameworkModule.CreatInstance(type, chunck, name);

            mou.Bind(this);
            return(mou);
        }
Пример #3
0
        /// <summary>
        /// 创建实例
        /// </summary>
        /// <param name="type">模块类型</param>
        /// <param name="chunck">代码块</param>
        /// <param name="name">模块名称</param>
        /// <returns></returns>
        public static FrameworkModule CreatInstance(Type type, string chunck, string name = "")
        {
            FrameworkModule moudle = Activator.CreateInstance(type,
                                                              BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                                                              null, null, null) as FrameworkModule;

            if (moudle != null)
            {
                moudle._binded     = false;
                moudle._disposed   = false;
                moudle._chunck     = chunck;
                moudle._moudleType = moudle.GetType().Name;
                if (string.IsNullOrEmpty(name))
                {
                    moudle._name = string.Format("{0}.{1}", moudle._chunck, moudle._moudleType);
                }
                else
                {
                    moudle._name = name;
                }

                moudle.Awake();
                moudle.enable = true;
            }
            else
            {
                Log.E(string.Format("Type: {0} Non Public Ctor With 0 para Not Find", type));
            }

            return(moudle);
        }
        internal bool UnSubscribeBindModule(FrameworkModule moudle)
        {
            Type type = moudle.GetType();

            if (!moudle_dic.ContainsKey(type))
            {
                Log.E(string.Format("01,Have Not Bind Module | Type {0}  Name {1}", type, moudle.name));
                return(false);
            }
            else
            {
                var tmpModule = moudle_dic[type].Find((m) => { return(moudle.name == m.name); });
                if (tmpModule == null)
                {
                    Log.E(string.Format("02,Have Not Bind Module | Type {0}  Name {1}", type, moudle.name));
                    return(false);
                }
                else
                {
                    moudle_list.Remove(moudle);
                    moudle_dic[type].Remove(moudle);
                    return(true);
                }
            }
        }
Пример #5
0
        internal bool SubscribeModule(FrameworkModule moudle)
        {
            Type type = moudle.GetType();

            if (!moudle_dic.ContainsKey(type))
            {
                moudle_dic.Add(type, new List <FrameworkModule>());
            }
            var list      = moudle_dic[type];
            var tmpModule = list.Find((m) => { return(moudle.name == m.name); });

            if (tmpModule == null)
            {
                list.Add(moudle);
                if (moudle is UpdateFrameworkModule)
                {
                    update_list.Add(moudle as UpdateFrameworkModule);
                }
                return(true);
            }
            else
            {
                Log.E(string.Format("Have Bind Module | Type {0}  Name {1}", type, moudle.name));
                return(false);
            }
        }