UnitListComponentSystem.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 
  2. namespace ET.Client
  3. {
  4. [ObjectSystem]
  5. public class UnitListComponentAwakeSystem : AwakeSystem<UnitListComponent>
  6. {
  7. protected override void Awake(UnitListComponent self)
  8. {
  9. UnitListComponent.Instance = self;
  10. self.RecycleUnits();
  11. self.UnitList = new();
  12. }
  13. }
  14. [ObjectSystem]
  15. public class UnitListComponentDestroySystem : DestroySystem<UnitListComponent>
  16. {
  17. protected override void Destroy(UnitListComponent self)
  18. {
  19. self.RecycleUnits();
  20. UnitListComponent.Instance = null;
  21. }
  22. }
  23. [FriendOf(typeof(UnitListComponent))]
  24. public static class UnitListComponentExt
  25. {
  26. public static void RecycleUnits(this UnitListComponent self)
  27. {
  28. if(self.UnitList != null)
  29. {
  30. foreach(var kp in self.UnitList)
  31. {
  32. kp.Value.OnSleep();
  33. }
  34. self.UnitList = null;
  35. }
  36. }
  37. }
  38. }