using System; using System.Collections.Generic; namespace ET { public class ConfigComponentAwakeSystem : AwakeSystem { public override void Awake(ConfigComponent self) { ConfigComponent.Instance = self; self.Load(); } } public class ConfigComponentLoadSystem : LoadSystem { public override void Load(ConfigComponent self) { self.Load(); } } public static class ConfigComponentSystem { public static void Load(this ConfigComponent self) { self.allConfig.Clear(); HashSet 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; 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.LoadAsync(); iCategory.EndInit(); self.allConfig[iCategory.ConfigType] = iCategory; } } public static T Get(this ConfigComponent self,long id)where T:class { if(self.allConfig.TryGetValue(typeof(T),out ACategory aCategory)) { return aCategory.TryGet(id) as T; } return null; } public static IEnumerable GetAll(this ConfigComponent self) where T : class { if (self.allConfig.TryGetValue(typeof(T), out ACategory aCategory)) { return aCategory.GetAll(); } return null; } } }