UnitComponentSystem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Linq;
  2. namespace ET
  3. {
  4. public class UnitComponentAwakeSystem: AwakeSystem<UnitComponent>
  5. {
  6. public override void Awake(UnitComponent self)
  7. {
  8. }
  9. }
  10. public class UnitComponentDestroySystem: DestroySystem<UnitComponent>
  11. {
  12. public override void Destroy(UnitComponent self)
  13. {
  14. self.idUnits.Clear();
  15. }
  16. }
  17. public static class UnitComponentSystem
  18. {
  19. public static void Add(this UnitComponent self, Unit unit)
  20. {
  21. unit.Parent = self;
  22. self.idUnits.Add(unit.Id, unit);
  23. }
  24. public static Unit Get(this UnitComponent self, long id)
  25. {
  26. self.idUnits.TryGetValue(id, out Unit unit);
  27. return unit;
  28. }
  29. public static void Remove(this UnitComponent self, long id)
  30. {
  31. Unit unit;
  32. self.idUnits.TryGetValue(id, out unit);
  33. self.idUnits.Remove(id);
  34. unit?.Dispose();
  35. }
  36. public static void RemoveNoDispose(this UnitComponent self, long id)
  37. {
  38. self.idUnits.Remove(id);
  39. }
  40. public static Unit[] GetAll(this UnitComponent self)
  41. {
  42. return self.idUnits.Values.ToArray();
  43. }
  44. }
  45. }