IEnumerator StartQuery() { NavMeshWorld world = NavMeshWorld.GetDefaultWorld(); NavMeshQuery query = new NavMeshQuery(world, Allocator.Persistent, maxPath); NavMeshLocation startLocation = query.MapLocation(start.position, Vector3.up * extents, 0); NavMeshLocation endLocation = query.MapLocation(end.position, Vector3.up * extents, 0); PathQueryStatus status = query.BeginFindPath(startLocation, endLocation); yield return(new WaitWhile(() => { status = query.UpdateFindPath(8, out int iterationsPerformed); return status == PathQueryStatus.InProgress; })); status = query.EndFindPath(out int pathsize); NativeArray <PolygonId> path = new NativeArray <PolygonId>(pathsize, Allocator.Temp); int pathResult = query.GetPathResult(path); //NativeArray<NavMeshLocation> pathStraight = new NativeArray<NavMeshLocation>(maxPath, Allocator.Temp); ////NativeArray<StraightPathFlag> pathStreaigthFlag = new NativeArray<StraightPathFlags>(maxPath, Allocator.Temp); //NativeArray<float> vertexSize = new NativeArray<float>(maxPath, Allocator.Temp); // //int straghtPathCount = 0; for (var i = 0; i < pathResult; i++) { var p = path[i]; var loc = query.CreateLocation(start.position, p); var target = loc.position; } query.Dispose(); }
public NavMeshLocation CreateLocation(Vector3 position, PolygonId polygon) { AtomicSafetyHandle.CheckReadAndThrow(this.m_Safety); Vector3 position2; PathQueryStatus closestPointOnPoly = NavMeshQuery.GetClosestPointOnPoly(this.m_NavMeshQuery, polygon, position, out position2); return(((closestPointOnPoly & PathQueryStatus.Success) != (PathQueryStatus)0) ? new NavMeshLocation(position2, polygon) : default(NavMeshLocation)); }
public void Execute() { nml_FromLocation = query.MapLocation(fromLocation, extents, 0); nml_ToLocation = query.MapLocation(toLocation, extents, 0); if (query.IsValid(nml_FromLocation) && query.IsValid(nml_ToLocation)) { status = query.BeginFindPath(nml_FromLocation, nml_ToLocation, -1); if (status == PathQueryStatus.InProgress) { status = query.UpdateFindPath(maxIteration, out int iterationPerformed); } if (status == PathQueryStatus.Success) { status = query.EndFindPath(out int polygonSize); NativeArray <NavMeshLocation> res = new NativeArray <NavMeshLocation>(polygonSize, Allocator.Temp); NativeArray <StraightPathFlags> straightPathFlag = new NativeArray <StraightPathFlags>(maxPathSize, Allocator.Temp); NativeArray <float> vertexSide = new NativeArray <float>(maxPathSize, Allocator.Temp); NativeArray <PolygonId> polys = new NativeArray <PolygonId>(polygonSize, Allocator.Temp); int straightPathCount = 0; query.GetPathResult(polys); returningStatus = PathUtils.FindStraightPath( query, fromLocation, toLocation, polys, polygonSize, ref res, ref straightPathFlag, ref vertexSide, ref straightPathCount, maxPathSize ); if (returningStatus == PathQueryStatus.Success) { int fromKey = ((int)fromLocation.x + (int)fromLocation.y + (int)fromLocation.z) * maxPathSize; int toKey = ((int)toLocation.x + (int)toLocation.y + (int)toLocation.z) * maxPathSize; int key = fromKey + toKey; statusOutput[0] = 1; statusOutput[1] = key; statusOutput[2] = straightPathCount; for (int i = 0; i < straightPathCount; i++) { result[i] = (float3)res[i].position + new float3(0, 0.75f, 0); // elevated point ub.Add(new Unit_Buffer { wayPoints = result[i] }); } } res.Dispose(); straightPathFlag.Dispose(); polys.Dispose(); vertexSide.Dispose(); } } }
public unsafe PathQueryStatus Raycast(out NavMeshHit hit, NavMeshLocation start, Vector3 targetPosition, int areaMask = -1, NativeArray <float> costs = default(NativeArray <float>)) { AtomicSafetyHandle.CheckReadAndThrow(this.m_Safety); bool flag = costs.Length != 0; if (flag) { bool flag2 = costs.Length != 32; if (flag2) { throw new ArgumentException(string.Format("The number of costs ({0}) must be exactly {1}, one for each possible area type.", costs.Length, 32), "costs"); } } void * costs2 = (costs.Length == 32) ? costs.GetUnsafePtr <float>() : null; int num; PathQueryStatus pathQueryStatus = NavMeshQuery.Raycast(this.m_NavMeshQuery, start, targetPosition, areaMask, costs2, out hit, null, out num, 0); return(pathQueryStatus & ~PathQueryStatus.BufferTooSmall); }
/// <summary>Returns true if a status `a` has `b`. Note that a /// PathQueryStatus is a set of flags which can be simultaneously /// active.</summary> public static bool HasStatus(PathQueryStatus a, PathQueryStatus b) => (a & b) == a;
public NavAgent(NavMeshLocation navMeshLocation, PathQueryStatus pathQueryStatus) { NavMeshLocation = navMeshLocation; PathQueryStatus = pathQueryStatus; }
public static bool IsFailure(this PathQueryStatus status) { return((status & PathQueryStatus.Failure) != 0); }
public static bool IsSuccess(this PathQueryStatus status) { return((status & PathQueryStatus.Success) != 0); }
public static bool IsInProgress(this PathQueryStatus status) { return((status & PathQueryStatus.InProgress) != 0); }
public void Update(int maxIter = 100) { var s = state[0]; PathQueryStatus status = PathQueryStatus.Success; if (s.entitySize == 0) { return; } while (maxIter > 0) { if (s.entityInUse == State.NONE) { PathRequestData request = requests[0]; for (int i = s.entitySize - 1; i >= 0; --i) { request = requests[i]; if (request.status < PathRequestStatus.Done) { s.entityInUse = i; break; } } if (s.entityInUse == State.NONE) { break; } var startLoc = query.MapLocation(request.start, Vector3.one * 10f, request.agentType, request.mask); var endLoc = query.MapLocation(request.end, Vector3.one * 10f, request.agentType, request.mask); status = query.BeginFindPath(startLoc, endLoc, request.mask); if (status.IsFailure()) { break; } request.status = PathRequestStatus.InProgress; requests[s.entityInUse] = request; } int nIter; status = query.UpdateFindPath(maxIter, out nIter); if (status.IsFailure()) { break; } maxIter -= nIter; if (status.IsSuccess()) { int pathSize; var request = requests[s.entityInUse]; status = query.EndFindPath(out pathSize); if (status.IsFailure()) { break; } if (status.IsSuccess()) { query.GetPathResult(resultBuffer); var offset = s.pathSize; var pathSlice = new NativeSlice <PathPoint>(pathBuffer, offset); status = PathUtils.FindStraightPath(query, request.start, request.end, resultBuffer, pathSize , pathSlice, ref pathSize, MAX_PATHSIZE); if (status.IsFailure()) { break; } pathStart[s.entityInUse] = offset; request.pathSize = pathSize; s.pathSize += pathSize; } request.status = PathRequestStatus.Done; requests[s.entityInUse] = request; s.entityInUse = State.NONE; } state[0] = s; } if (status.IsFailure()) { var request = requests[s.entityInUse]; request.status = PathRequestStatus.Failure; requests[s.entityInUse] = request; s.entityInUse = State.NONE; state[0] = s; } }