CellSystem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using System.Text;
  3. namespace ET.Server
  4. {
  5. [FriendOf(typeof(Cell))]
  6. public static class CellSystem
  7. {
  8. [ObjectSystem]
  9. public class CellDestroySystem: DestroySystem<Cell>
  10. {
  11. protected override void Destroy(Cell self)
  12. {
  13. self.AOIUnits.Clear();
  14. self.SubsEnterEntities.Clear();
  15. self.SubsLeaveEntities.Clear();
  16. }
  17. }
  18. public static void Add(this Cell self, AOIEntity aoiEntity)
  19. {
  20. self.AOIUnits.Add(aoiEntity.Id, aoiEntity);
  21. }
  22. public static void Remove(this Cell self, AOIEntity aoiEntity)
  23. {
  24. self.AOIUnits.Remove(aoiEntity.Id);
  25. }
  26. public static string CellIdToString(this long cellId)
  27. {
  28. int y = (int) (cellId & 0xffffffff);
  29. int x = (int) ((ulong) cellId >> 32);
  30. return $"{x}:{y}";
  31. }
  32. public static string CellIdToString(this HashSet<long> cellIds)
  33. {
  34. StringBuilder sb = new StringBuilder();
  35. foreach (long cellId in cellIds)
  36. {
  37. sb.Append(cellId.CellIdToString());
  38. sb.Append(",");
  39. }
  40. return sb.ToString();
  41. }
  42. }
  43. }