Пример #1
0
        /// <summary>
        /// 玩家寻路组件对外接口 消息处理方法中使用
        /// </summary>
        public static async ETVoid MoveTo(this GamerPathComponent self, Vector3 target)
        {
            if ((self.Target - target).magnitude < 0.1f)
            {
                return;
            }

            self.Target = target;

            Gamer gamer = self.GetParent <Gamer>();

            //全局寻路组件 用于计算路径
            PathfindingComponent pathfindingComponent = Game.Scene.GetComponent <PathfindingComponent>();

            self.ABPath = ComponentFactory.Create <ETModel.ABPath, Vector3, Vector3>(gamer.Position,
                                                                                     new Vector3(target.x, target.y, target.z)); //创建路径 寻路组件的接口
            pathfindingComponent.Search(self.ABPath);
            //Log.Debug($"寻路查询结果: {self.ABPath.Result.ListToString()}");

            self.CancellationTokenSource?.Cancel();   //取消当前寻路
            self.CancellationTokenSource = new CancellationTokenSource();
            await self.MoveAsync(self.ABPath.Result); //开始移动

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
Пример #2
0
        public static async ETVoid MoveTo(this UnitPathComponent self, Vector3 target)
        {
            if ((self.Target - target).magnitude < 0.1f)
            {
                return;
            }

            self.Target = target;

            Unit unit = self.GetParent <Unit>();


            PathfindingComponent pathfindingComponent = Game.Scene.GetComponent <PathfindingComponent>();

            self.ABPath = ComponentFactory.Create <ETModel.ABPath, Vector3, Vector3>(unit.Position,
                                                                                     new Vector3(target.x, target.y, target.z));
            pathfindingComponent.Search(self.ABPath);
            Log.Debug($"find result: {self.ABPath.Result.ListToString()}");

            self.CancellationTokenSource?.Cancel();
            self.CancellationTokenSource = new CancellationTokenSource();
            await self.MoveAsync(self.ABPath.Result);

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
Пример #3
0
        public static async ETVoid MoveTo(this MapPathComponent self, Vector3 target)
        {
            if ((self.Target - target).magnitude < 0.1f)
            {
                return;
            }

            self.Target = target;
            Unit unit = self.GetParent <Unit>();

            PathfindingComponent pathfindingComponent = Game.Scene.GetComponent <PathfindingComponent>();

            self.ABPath = ComponentFactory.Create <ABPathWrap, Vector3, Vector3>(unit.Position, new Vector3(target.x, target.y, target.z));
            pathfindingComponent.Search(self.ABPath);

            self.CancellationTokenSource?.Cancel();
            self.CancellationTokenSource = new CancellationTokenSource();

            //ToTo 同步到服务端 本身坐标和向量坐标
            await self.MoveAsync(self.ABPath.Result);

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }