UnitComponent.cs 660 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. namespace Hotfix
  3. {
  4. [EntityEvent(EntityEventId.UnitComponent)]
  5. public class UnitComponent: Component
  6. {
  7. private readonly Dictionary<long, Unit> idUnits = new Dictionary<long, Unit>();
  8. public void Add(Unit unit)
  9. {
  10. this.idUnits.Add(unit.Id, unit);
  11. }
  12. public Unit Get(long id)
  13. {
  14. Unit unit;
  15. this.idUnits.TryGetValue(id, out unit);
  16. return unit;
  17. }
  18. public void Remove(long id)
  19. {
  20. this.idUnits.Remove(id);
  21. }
  22. public override void Dispose()
  23. {
  24. if (this.Id == 0)
  25. {
  26. return;
  27. }
  28. base.Dispose();
  29. foreach (Unit unit in this.idUnits.Values)
  30. {
  31. unit.Dispose();
  32. }
  33. }
  34. }
  35. }