Example #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;
        }