MoveHelper.cs 912 B

123456789101112131415161718192021222324
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. public static class MoveHelper
  6. {
  7. // 可以多次调用,多次调用的话会取消上一次的协程
  8. public static async ETTask<int> MoveToAsync(this Unit unit, Vector3 targetPos, ETCancellationToken cancellationToken = null)
  9. {
  10. C2M_PathfindingResult msg = new C2M_PathfindingResult();
  11. unit.Domain.GetComponent<SessionComponent>().Session.Send(msg);
  12. ObjectWait objectWait = unit.GetComponent<ObjectWait>();
  13. // 要取消上一次的移动协程
  14. objectWait.Notify(new WaitType.Wait_UnitStop() { Error = WaitTypeError.Cancel });
  15. // 一直等到unit发送stop
  16. WaitType.Wait_UnitStop waitUnitStop = await objectWait.Wait<WaitType.Wait_UnitStop>();
  17. return waitUnitStop.Error;
  18. }
  19. }
  20. }