public ABPath GetNewPath(Vector3 start, Vector3 end) { return(ABPath.Construct(start, end, null)); }
private void DemoPath() { Path path = null; if (this.activeDemo == PathTypesDemo.DemoMode.ABPath) { path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete)); if (this.agents != null && this.agents.Length > 0) { List <Vector3> list = ListPool <Vector3> .Claim(this.agents.Length); Vector3 vector = Vector3.zero; for (int i = 0; i < this.agents.Length; i++) { list.Add(this.agents[i].transform.position); vector += list[i]; } vector /= (float)list.Count; for (int j = 0; j < this.agents.Length; j++) { List <Vector3> list2; List <Vector3> expr_B8 = list2 = list; int index; int expr_BD = index = j; Vector3 a = list2[index]; expr_B8[expr_BD] = a - vector; } PathUtilities.GetPointsAroundPoint(this.end.position, AstarPath.active.graphs[0] as IRaycastableGraph, list, 0f, 0.2f); for (int k = 0; k < this.agents.Length; k++) { if (!(this.agents[k] == null)) { this.agents[k].target.position = list[k]; this.agents[k].UpdatePath(); } } } } else if (this.activeDemo == PathTypesDemo.DemoMode.MultiTargetPath) { MultiTargetPath multiTargetPath = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, new OnPathDelegate(this.OnPathComplete)); path = multiTargetPath; } else if (this.activeDemo == PathTypesDemo.DemoMode.RandomPath) { RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); randomPath.spread = this.spread; randomPath.aimStrength = this.aimStrength; randomPath.aim = this.end.position; path = randomPath; } else if (this.activeDemo == PathTypesDemo.DemoMode.FleePath) { FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete)); fleePath.aimStrength = this.aimStrength; fleePath.spread = this.spread; path = fleePath; } else if (this.activeDemo == PathTypesDemo.DemoMode.ConstantPath) { base.StartCoroutine(this.CalculateConstantPath()); path = null; } else if (this.activeDemo == PathTypesDemo.DemoMode.FloodPath) { FloodPath floodPath = FloodPath.Construct(this.end.position, null); this.lastFlood = floodPath; path = floodPath; } else if (this.activeDemo == PathTypesDemo.DemoMode.FloodPathTracer && this.lastFlood != null) { FloodPathTracer floodPathTracer = FloodPathTracer.Construct(this.end.position, this.lastFlood, new OnPathDelegate(this.OnPathComplete)); path = floodPathTracer; } if (path != null) { AstarPath.StartPath(path, false); this.lastPath = path; } }
/// <summary> /// Called when a requested path has finished calculation. /// A path is first requested by <see cref="SearchPath"/>, it is then calculated, probably in the same or the next frame. /// Finally it is returned to the seeker which forwards it to this function.\n /// </summary> protected override void OnPathComplete(Path _p) { ABPath p = _p as ABPath; if (p == null) { throw new System.Exception("This function only handles ABPaths, do not use special path types"); } waitingForPathCalculation = false; //Claim the new path p.Claim(this); // Path couldn't be calculated of some reason. // More info in p.errorLog (debug string) if (p.error) { p.Release(this); return; } //Release the previous path if (path != null) { path.Release(this); } //Replace the old path path = p; //Reset some variables currentWaypointIndex = 0; reachedEndOfPath = false; //The next row can be used to find out if the path could be found or not //If it couldn't (error == true), then a message has probably been logged to the console //however it can also be got using p.errorLog //if (p.error) if (closestOnPathCheck) { // Simulate movement from the point where the path was requested // to where we are right now. This reduces the risk that the agent // gets confused because the first point in the path is far away // from the current position (possibly behind it which could cause // the agent to turn around, and that looks pretty bad). Vector3 p1 = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint; Vector3 p2 = GetFeetPosition(); Vector3 dir = p2 - p1; float magn = dir.magnitude; dir /= magn; int steps = (int)(magn / pickNextWaypointDist); #if ASTARDEBUG Debug.DrawLine(p1, p2, Color.red, 1); #endif for (int i = 0; i <= steps; i++) { CalculateVelocity(p1); p1 += dir; } } }
public ABPath GetNewPath(ref VInt3 start, ref VInt3 end) { return(ABPath.Construct(ref start, ref end, null)); }