protected override async ETVoid Run(Session session, M2C_DPathfindingResult message) { DUnit unit = session.Domain.GetComponent <DUnitComponent>().Get(message.Id); Vector3 servierpos = new Vector3(message.X, message.Y, message.Z); using var list = ListComponent <Vector3> .Create(); for (int i = 0; i < message.Xs.Count; ++i) { list.List.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i])); } await DMoveAction.MoveActionImpAsync(unit, list.List.ToArray(), servierpos); }
public static async ETTask<int> MoveActionAsync(DUnit unit, Vector3 targetPos, ETCancellationToken cancellationToken = null) { NavMeshPath meshPath = new NavMeshPath(); NavMesh.CalculatePath(unit.Position, targetPos, 1, meshPath); if (unit.DomainScene().GetComponent<PVPComponent>().bePVP) { if (OperationerComponentSystem.IsOperationer(unit) == false) { return WaitTypeError.Success; } // PVP 发送移动消息,封包发送 C2M_DPathfindingResult msg = new C2M_DPathfindingResult(); msg.Id = unit.Id; msg.X = unit.Position.x; msg.Y = unit.Position.y; msg.Z = unit.Position.z; for (int i = 0; i < meshPath.corners.Length; i++) { msg.Xs.Add(meshPath.corners[i].x); msg.Ys.Add(meshPath.corners[i].y); msg.Zs.Add(meshPath.corners[i].z); } unit.Domain.GetComponent<SessionComponent>().Session.Send(msg); ObjectWait objectWait = unit.GetComponent<ObjectWait>(); objectWait.Notify(new WaitType.Wait_UnitStop() { Error = WaitTypeError.Cancel }); WaitType.Wait_UnitStop waitUnitStop = await objectWait.Wait<WaitType.Wait_UnitStop>(cancellationToken); return waitUnitStop.Error; } else { return await DMoveAction.MoveActionImpAsync(unit, meshPath.corners, unit.Position, cancellationToken); } }