UnitComponentSystem.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. self.idUnits.Add(unit.Id, unit);
  22. }
  23. public static Unit Get(this UnitComponent self, long id)
  24. {
  25. self.idUnits.TryGetValue(id, out Unit unit);
  26. return unit;
  27. }
  28. public static void Remove(this UnitComponent self, long id)
  29. {
  30. Unit unit;
  31. self.idUnits.TryGetValue(id, out unit);
  32. self.idUnits.Remove(id);
  33. unit?.Dispose();
  34. }
  35. public static void RemoveNoDispose(this UnitComponent self, long id)
  36. {
  37. self.idUnits.Remove(id);
  38. }
  39. public static Unit[] GetAll(this UnitComponent self)
  40. {
  41. return self.idUnits.Values.ToArray();
  42. }
  43. }
  44. }