ConfigComponentSystem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. public class ConfigAwakeSystem : AwakeSystem<ConfigComponent>
  6. {
  7. public override void Awake(ConfigComponent self)
  8. {
  9. ConfigComponent.Instance = self;
  10. self.Awake();
  11. }
  12. }
  13. public class ConfigLoadSystem : LoadSystem<ConfigComponent>
  14. {
  15. public override void Load(ConfigComponent self)
  16. {
  17. self.Load();
  18. }
  19. }
  20. public class ConfigDestroySystem : DestroySystem<ConfigComponent>
  21. {
  22. public override void Destroy(ConfigComponent self)
  23. {
  24. ConfigComponent.Instance = null;
  25. }
  26. }
  27. public static class ConfigComponentSystem
  28. {
  29. public static void Awake(this ConfigComponent self)
  30. {
  31. self.Load();
  32. }
  33. public static void Load(this ConfigComponent self)
  34. {
  35. self.AllConfig.Clear();
  36. HashSet<Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));
  37. foreach (Type type in types)
  38. {
  39. object obj = Activator.CreateInstance(type);
  40. ACategory iCategory = obj as ACategory;
  41. if (iCategory == null)
  42. {
  43. throw new Exception($"class: {type.Name} not inherit from ACategory");
  44. }
  45. iCategory.BeginInit();
  46. iCategory.EndInit();
  47. self.AllConfig[iCategory.ConfigType] = iCategory;
  48. }
  49. }
  50. }
  51. }