예제 #1
0
        // 可以多次调用,多次调用的话会取消上一次的协程
        public static async ETTask <int> MoveToAsync(this Unit unit, Vector3 targetPos, ETCancellationToken cancellationToken = null)
        {
            if (!unit.GetComponent <MoveComponent>().Enable)
            {
                Log.Error("暂时无法移动");
                return(1);
            }
            C2M_PathfindingResult msg = new C2M_PathfindingResult()
            {
                X = targetPos.x, Y = targetPos.y, Z = targetPos.z
            };

            unit.ZoneScene().GetComponent <SessionComponent>().Session.Send(msg);

            ObjectWait objectWait = unit.GetComponent <ObjectWait>();

            // 要取消上一次的移动协程
            objectWait.Notify(new WaitType.Wait_UnitStop()
            {
                Error = WaitTypeError.Cancel
            });

            // 一直等到unit发送stop
            WaitType.Wait_UnitStop waitUnitStop = await objectWait.Wait <WaitType.Wait_UnitStop>(cancellationToken);

            return(waitUnitStop.Error);
        }
예제 #2
0
        // 可以多次调用,多次调用的话会取消上一次的协程
        public static async ETTask <int> MoveToAsync(this Unit unit, Vector3 targetPos, ETCancellationToken cancellationToken = null)
        {
            C2M_PathfindingResult msg = new C2M_PathfindingResult();

            unit.Domain.GetComponent <SessionComponent>().Session.Send(msg);

            ObjectWait objectWait = unit.GetComponent <ObjectWait>();

            // 要取消上一次的移动协程
            objectWait.Notify(new WaitType.Wait_UnitStop()
            {
                Error = WaitTypeError.Cancel
            });

            // 一直等到unit发送stop
            WaitType.Wait_UnitStop waitUnitStop = await objectWait.Wait <WaitType.Wait_UnitStop>();

            return(waitUnitStop.Error);
        }
예제 #3
0
        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);
            }
        }