ChangePosition_NotifyAOI.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. namespace ET.Server
  3. {
  4. [Event]
  5. public class ChangePosition_NotifyAOI: AEvent<ET.EventType.ChangePosition>
  6. {
  7. protected override async ETTask Run(ET.EventType.ChangePosition args)
  8. {
  9. Unit unit = args.Unit;
  10. // 机器人也有Unit,机器人的Unit在Current Scene
  11. if (unit.DomainScene().SceneType != SceneType.Map)
  12. {
  13. return;
  14. }
  15. Vector3 oldPos = args.OldPos;
  16. int oldCellX = (int) (oldPos.x * 1000) / AOIManagerComponent.CellSize;
  17. int oldCellY = (int) (oldPos.z * 1000) / AOIManagerComponent.CellSize;
  18. int newCellX = (int) (unit.Position.x * 1000) / AOIManagerComponent.CellSize;
  19. int newCellY = (int) (unit.Position.z * 1000) / AOIManagerComponent.CellSize;
  20. if (oldCellX == newCellX && oldCellY == newCellY)
  21. {
  22. return;
  23. }
  24. AOIEntity aoiEntity = unit.GetComponent<AOIEntity>();
  25. if (aoiEntity == null)
  26. {
  27. return;
  28. }
  29. unit.Domain.GetComponent<AOIManagerComponent>().Move(aoiEntity, newCellX, newCellY);
  30. await ETTask.CompletedTask;
  31. }
  32. }
  33. }