ChangePosition_NotifyAOI.cs 1.0 KB

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