ChangePosition_NotifyAOI.cs 1.1 KB

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