ConfigComponentSystem.cs 1.4 KB

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