private void FindPath() { NavStatus status = mGroup.query.FindPath( mPathStart, mPathEnd, mGroup.filter, mPath.buffer, out mPathCount); mCorridor.Reset(mPathStart); if (NavUtil.Succeeded(status) && mPathCount > 0) { mCorridor.SetCorridor(mPathEnd.point, mPath.buffer, mPathCount); } }
public PathCorridor GeneratePathCorridor(Vector3 start, Vector3 end) { if (NavUtil.Failed(GetNavMeshPoint(start, new oVector3(0.3f, 2, 0.3f), out NavmeshPoint origin)) || origin.point == new oVector3()) { return(null); } if (NavUtil.Failed(GetNavMeshPoint(end, new oVector3(0.3f, 2, 0.3f), out NavmeshPoint destination)) || destination.point == new oVector3()) { return(null); } uint[] path = new uint[250]; int pathCount; if (origin.polyRef == destination.polyRef) { pathCount = 1; path[0] = origin.polyRef; } else { NavStatus status = _query.FindPath(origin, destination, _filter, path, out pathCount); if (NavUtil.Failed(status) || pathCount == 0) { // Handle pathfinding failure. throw new Exception("path failed: " + status); } else if (destination.polyRef != path[pathCount - 1]) { //Chat.WriteLine("Unable to generate full path: " + status); //throw new Exception("Unable to generate full path: " + status); //return null; } } _pathCorridor.SetCorridor(end.ToCAIVector3(), path, pathCount); _pathCorridor.Move(start.ToCAIVector3(), end.ToCAIVector3()); return(_pathCorridor); }
/// <summary> /// Finds a path from the start point to the end point and loads it into the corridor. /// </summary> /// <remarks> /// <para> /// <b>Warning</b>: The corridor must be available before calling this method. /// </para> /// <para> /// The input points are all expected to be valid. (E.g. polyRef != 0) /// </para> /// </remarks> /// <param name="start"> /// A valid navigation mesh point representing the start of the path. /// </param> /// <param name="end"> /// A valid navigation mesh point representing the end of the path. /// </param> /// <returns>The length of the path, or -1 on failure.</returns> public int PlanCorridor(NavmeshPoint start, NavmeshPoint end) { // Note: Don't try to re-use the current corridor. Unlike // paths, the corridor is more likely to become malformed // over time. int pathCount; if (start.polyRef == 0 || end.polyRef == 0 || corridor == null) { return(-1); } if (start.polyRef == end.polyRef) { corridor.Reset(start); corridor.MoveTarget(end.point); data.navStatus = NavStatus.Sucess; return(1); } else { data.navStatus = navGroup.query.FindPath(start , end , navGroup.filter , agentGroup.pathBuffer , out pathCount); } corridor.Reset(start); if (pathCount > 0) { corridor.SetCorridor(end.point , agentGroup.pathBuffer , pathCount); } return(pathCount); }
//寻找路线:查找从起点到终点的路径,并将其加载到道路中 public int PlanCorridor(NavmeshPoint start, NavmeshPoint end) { //原作标识:不要尝试重用corridor,这个东西有更多的可能性变得很畸形 int pathCount; //如果点不可用就会直接失败 if (start.polyRef == 0 || end.polyRef == 0 || corridor == null) { return(-1); } //如果相同点直接结束,navStatus更新 if (start.polyRef == end.polyRef) { corridor.Reset(start); corridor.MoveTarget(end.point); navStatus = NavStatus.Sucess; return(1); } else { //调用NavmeshQuery的方法进行寻路,然后内部走NavmeshQueryEx类调用dll //最后初步猜测调用Detour的DetourNavMeshQuery(有待考证) navStatus = navGroup.query.FindPath(start, end, navGroup.filter, agentGroup.pathBuffer, out pathCount); } corridor.Reset(start); if (pathCount > 0) { corridor.SetCorridor(end.point, agentGroup.pathBuffer, pathCount); } return(pathCount); }