CellSystem.cs 1.3 KB

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