public bool GeneratePolyPath(Vector3 startPos, Vector3 endPos) { polyResult.Initialize(); NavmeshPoint startPoint; NavmeshPoint endPoint; NavStatus status0 = query.GetNearestPoint(startPos, Vector3.one, mCrowdManager.QueryFilter, out startPoint); NavStatus status1 = query.GetNearestPoint(endPos, Vector3.one, mCrowdManager.QueryFilter, out endPoint); NavStatus status = query.FindPath(startPoint, endPoint , mCrowdManager.QueryFilter, polyResult , out polyResultCount); //Debug.Log("GenerateNavPathResult:" + startPoint.point.ToString() + "~" + endPoint.point.ToString() + ":" + polyResultCount.ToString()); //string result = ""; //for (int i = 0; i < polyResultCount; i++) //{ // result += polyResult[i].ToString() + ";"; //} //Debug.Log(result); if ((status & NavStatus.Sucess) == 0) { return(false); } return(true); }
public List <Vector3> GeneratePath(Vector3 start, Vector3 end) { List <Vector3> finalPath = new List <Vector3>(); if (NavUtil.Failed(GetNavMeshPoint(start, new oVector3(0.5f, 2, 0.5f), out NavmeshPoint origin)) || origin.point == new oVector3()) { throw new PointNotOnNavMeshException(start); } if (NavUtil.Failed(GetNavMeshPoint(end, new oVector3(0.5f, 2, 0.5f), out NavmeshPoint destination)) || destination.point == new oVector3()) { throw new PointNotOnNavMeshException(end); } uint[] path = new uint[500]; int pathCount; if (origin.polyRef == destination.polyRef) { path[0] = origin.polyRef; pathCount = 1; } else { NavStatus status = _query.FindPath(origin, destination, _filter, path, out pathCount); if (NavUtil.Failed(status) || pathCount == 0) { Chat.WriteLine("FindPath failed?"); throw new Exception("FindPath 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); } } oVector3[] straightPath = StraightenPath(start.ToCAIVector3(), end.ToCAIVector3(), path, pathCount); finalPath.AddRange(straightPath.Select(node => new Vector3(node.x, node.y, node.z))); return(finalPath); }