Example #1
0
        public void Load()
        {
            this.allConfig.Clear();
            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                ConfigAttribute configAttribute = attrs[0] as ConfigAttribute;
                // 只加载指定的配置
                if (!configAttribute.Type.Is(AppType.ClientM))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                ACategory iCategory = obj as ACategory;
                if (iCategory == null)
                {
                    throw new Exception($"class: {type.Name} not inherit from ACategory");
                }
                iCategory.BeginInit();
                iCategory.EndInit();

                this.allConfig[iCategory.ConfigType] = iCategory;
            }
        }
Example #2
0
        public void Load()
        {
            this.allConfig.Clear();
            Type[] types = DllHelper.GetMonoTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);

                ACategory iCategory = obj as ACategory;
                if (iCategory == null)
                {
                    throw new Exception($"class: {type.Name} not inherit from ACategory");
                }
                iCategory.BeginInit();
                iCategory.EndInit();

                this.allConfig[iCategory.ConfigType] = iCategory;
            }
        }
Example #3
0
        public void Load()
        {
            this.allConfig.Clear();
            //先获取到所有加了ConfigAttribute的类
            List <Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                ConfigAttribute configAttribute = attrs[0] as ConfigAttribute;
                // 如果不是客户端的配置 遍历下一个元素
                if (!configAttribute.Type.Is(AppType.ClientM))
                {
                    continue;
                }
                object    obj       = Activator.CreateInstance(type);  //创建实例
                ACategory iCategory = obj as ACategory;                //转换类型 如果成功 不会等于null
                if (iCategory == null)
                {
                    throw new Exception($"class: {type.Name} not inherit from ACategory");
                }
                iCategory.BeginInit();                            //调用实例开始初始化的方法
                iCategory.EndInit();
                this.allConfig[iCategory.ConfigType] = iCategory; //加到缓存里
            }
        }