public void LocalPlayerWalkToDestination(Vector3 targetPos, Task relateTask = null)
        {
            Actor player = Game.GetInstance().GetLocalPlayer();

            if (player == null)
            {
                return;
            }

            targetPos.y = RoleHelp.GetHeightInScene(player.ActorId, targetPos.x, targetPos.z);
            targetPos   = InstanceHelper.ClampInWalkableRange(targetPos, 10);

            // 判断是否可到达
            XNavMeshPath walkMeshPath = new XNavMeshPath();

            XNavMesh.CalculatePath(player.transform.position, targetPos, xc.Dungeon.LevelManager.GetInstance().AreaExclude, walkMeshPath);
            if (walkMeshPath.status != XNavMeshPathStatus.PathComplete)
            {
                // 如果通过任务导航寻路,且在新手副本的不可到达区域,则直接飞过去,以免因为配置错误而导致卡死
                if (relateTask != null && SceneHelp.Instance.CurSceneID == GameConstHelper.GetUint("GAME_BORN_DUNGEON"))
                {
                    GameDebug.LogWarning(DBConstText.GetText("MAP_POS_CAN_NOT_REACH") + ",该场景是新手场景,直接瞬移过去");
                    player.MoveCtrl.SendFly(targetPos);
                    player.SetPosition(targetPos);
                }
                else
                {
                    UINotice.Instance.ShowMessage(DBConstText.GetText("MAP_POS_CAN_NOT_REACH"));
                }
                return;
            }

            InstanceManager.Instance.IsAutoFighting = false;

            mPathWalker.WalkTo(targetPos);
            //player.MoveCtrl.TryWalkTo(targetPos);

            /*
             * uint instanceType = InstanceManager.Instance.InstanceType;
             *
             * if (instanceType == GameConst.WAR_TYPE_WILD || instanceType == GameConst.WAR_TYPE_HOLE || instanceType == GameConst.WAR_SUBTYPE_WILD_PUB || instanceType == GameConst.WAR_TYPE_MULTI)
             * {
             *  if(mPathWalker == null)
             *  {
             *      return;
             *  }
             *
             *  mPathWalker.WalkTo(targetPos);
             * }
             * else
             * {
             *  player.MoveCtrl.TryWalkTo(targetPos);
             * }*/

            TaskNavigationActive(true);
            IsNavigating = true;
        }
Beispiel #2
0
 /// <summary>
 /// Calculate a path between two points and store the resulting path.
 /// </summary>
 /// <param name="sourcePosition">
 /// The initial position of the path requested.
 /// </param>
 /// <param name="targetPosition">
 /// The final position of the path requested.
 /// </param>
 /// <param name="exclude">
 ///
 /// </param>
 /// <param name="path">
 /// The resulting path.
 /// </param>
 /// <returns>
 /// True if a either a complete or partial path is found and false otherwise.
 /// </returns>
 public static bool CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, ushort exclude, XNavMeshPath path)
 {
     Vector3[] temp_corners = new Vector3[MAX_CORNER];
     path.status = DetourMgrEx.detourMgrFindPath(ref sourcePosition, ref targetPosition, temp_corners, exclude);
     if (path.status == XNavMeshPathStatus.PathComplete)
     {
         int len = temp_corners.Length;
         for (int i = 0; i < len; i++)
         {
             if (temp_corners[i] != Vector3.zero)
             {
                 path.AddCorner(temp_corners[i]);
             }
             else
             {
                 break;
             }
         }
         return(true);
     }
     return(false);
 }