UnitComponent.cs 1.1 KB

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