ConfigComponentSystem.cs 1.3 KB

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