UnitComponent.cs 651 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections.Generic;
  2. namespace Hotfix
  3. {
  4. [ObjectEvent(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. this.idUnits.TryGetValue(id, out Unit unit);
  15. return unit;
  16. }
  17. public void Remove(long id)
  18. {
  19. this.idUnits.Remove(id);
  20. }
  21. public override void Dispose()
  22. {
  23. if (this.Id == 0)
  24. {
  25. return;
  26. }
  27. base.Dispose();
  28. foreach (Unit unit in this.idUnits.Values)
  29. {
  30. unit.Dispose();
  31. }
  32. }
  33. }
  34. }