void DrawGizmoBezier(Vector3 p1, Vector3 p2) { var dir = p2 - p1; if (dir == Vector3.zero) { return; } var normal = Vector3.Cross(Vector3.up, dir); var normalUp = Vector3.Cross(dir, normal); normalUp = normalUp.normalized; normalUp *= dir.magnitude * 0.1f; var p1c = p1 + normalUp; var p2c = p2 + normalUp; var prev = p1; for (var i = 1; i <= 20; i++) { var t = i / 20.0f; var p = AstarMath.CubicBezier(p1, p1c, p2c, p2, t); Gizmos.DrawLine(prev, p); prev = p; } }
public override Vector3 ClosestPointOnNodeXZ(Vector3 _p) { INavmeshHolder navmeshHolder = GetNavmeshHolder(base.DataGroupIndex, base.GraphIndex); VInt3 vertex = navmeshHolder.GetVertex(this.v0); VInt3 lineEnd = navmeshHolder.GetVertex(this.v1); VInt3 num3 = navmeshHolder.GetVertex(this.v2); VInt3 point = (VInt3)_p; int y = point.y; vertex.y = 0; lineEnd.y = 0; num3.y = 0; point.y = 0; if ((((lineEnd.x - vertex.x) * (point.z - vertex.z)) - ((point.x - vertex.x) * (lineEnd.z - vertex.z))) > 0L) { float num6 = Mathf.Clamp01(AstarMath.NearestPointFactorXZ(vertex, lineEnd, point)); return((Vector3)(new Vector3(vertex.x + ((lineEnd.x - vertex.x) * num6), (float)y, vertex.z + ((lineEnd.z - vertex.z) * num6)) * 0.001f)); } if ((((num3.x - lineEnd.x) * (point.z - lineEnd.z)) - ((point.x - lineEnd.x) * (num3.z - lineEnd.z))) > 0L) { float num7 = Mathf.Clamp01(AstarMath.NearestPointFactorXZ(lineEnd, num3, point)); return((Vector3)(new Vector3(lineEnd.x + ((num3.x - lineEnd.x) * num7), (float)y, lineEnd.z + ((num3.z - lineEnd.z) * num7)) * 0.001f)); } if ((((vertex.x - num3.x) * (point.z - num3.z)) - ((point.x - num3.x) * (vertex.z - num3.z))) > 0L) { float num8 = Mathf.Clamp01(AstarMath.NearestPointFactorXZ(num3, vertex, point)); return((Vector3)(new Vector3(num3.x + ((vertex.x - num3.x) * num8), (float)y, num3.z + ((vertex.z - num3.z) * num8)) * 0.001f)); } return(_p); }
public Vector3 GetMovementVector(Vector3 point) { if (this.vectorPath == null || this.vectorPath.Count == 0) { return(Vector3.zero); } if (this.vectorPath.Count == 1) { return(this.vectorPath[0] - point); } float num = float.PositiveInfinity; int num2 = 0; for (int i = 0; i < this.vectorPath.Count - 1; i++) { Vector3 a = AstarMath.NearestPointStrict(this.vectorPath[i], this.vectorPath[i + 1], point); float sqrMagnitude = (a - point).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; num2 = i; } } return(this.vectorPath[num2 + 1] - point); }
public override Vector3 ClosestPointOnNodeXZ(Vector3 _p) { INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex); Int3 vertex = navmeshHolder.GetVertex(this.v0); Int3 vertex2 = navmeshHolder.GetVertex(this.v1); Int3 vertex3 = navmeshHolder.GetVertex(this.v2); Int3 point = (Int3)_p; int y = point.y; vertex.y = 0; vertex2.y = 0; vertex3.y = 0; point.y = 0; if ((long)(vertex2.x - vertex.x) * (long)(point.z - vertex.z) - (long)(point.x - vertex.x) * (long)(vertex2.z - vertex.z) > 0L) { float num = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex, vertex2, point)); return(new Vector3((float)vertex.x + (float)(vertex2.x - vertex.x) * num, (float)y, (float)vertex.z + (float)(vertex2.z - vertex.z) * num) * 0.001f); } if ((long)(vertex3.x - vertex2.x) * (long)(point.z - vertex2.z) - (long)(point.x - vertex2.x) * (long)(vertex3.z - vertex2.z) > 0L) { float num2 = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex2, vertex3, point)); return(new Vector3((float)vertex2.x + (float)(vertex3.x - vertex2.x) * num2, (float)y, (float)vertex2.z + (float)(vertex3.z - vertex2.z) * num2) * 0.001f); } if ((long)(vertex.x - vertex3.x) * (long)(point.z - vertex3.z) - (long)(point.x - vertex3.x) * (long)(vertex.z - vertex3.z) > 0L) { float num3 = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex3, vertex, point)); return(new Vector3((float)vertex3.x + (float)(vertex.x - vertex3.x) * num3, (float)y, (float)vertex3.z + (float)(vertex.z - vertex3.z) * num3) * 0.001f); } return(_p); }
void OnDrawGizmos(int boxi, int depth) { BBTreeBox box = arr[boxi]; var min = (Vector3) new Int3(box.rect.xmin, 0, box.rect.ymin); var max = (Vector3) new Int3(box.rect.xmax, 0, box.rect.ymax); Vector3 center = (min + max) * 0.5F; Vector3 size = (max - center) * 2; size = new Vector3(size.x, 1, size.z); center.y += depth * 2; Gizmos.color = AstarMath.IntToColor(depth, 1f); //new Color (0,0,0,0.2F); Gizmos.DrawCube(center, size); if (box.node != null) { } else { OnDrawGizmos(box.left, depth + 1); OnDrawGizmos(box.right, depth + 1); } }
public static void SimplifyPath2(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint) { int count = result.Count; if (end <= start + 1) { result.Add(nodes[start]); result.Add(nodes[end]); return; } GraphHitInfo graphHitInfo; if (rcg.Linecast(startPoint, endPoint, nodes[start], out graphHitInfo, result) || result[result.Count - 1] != nodes[end]) { result.RemoveRange(count, result.Count - count); int num = -1; float num2 = float.PositiveInfinity; for (int i = start + 1; i < end; i++) { float num3 = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (num == -1 || num3 < num2) { num = i; num2 = num3; } } RichFunnel.SimplifyPath2(rcg, nodes, start, num, result, startPoint, (Vector3)nodes[num].position); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath2(rcg, nodes, num, end, result, (Vector3)nodes[num].position, endPoint); } }
public virtual Color NodeColor(GraphNode node, PathHandler data) { Color result = AstarColor.NodeConnection; bool flag = false; if (node == null) { return(AstarColor.NodeConnection); } GraphDebugMode debugMode = AstarPath.active.debugMode; switch (debugMode) { case GraphDebugMode.Penalty: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (node.Penalty - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); flag = true; goto IL_A9; case GraphDebugMode.Connections: IL_33: if (debugMode != GraphDebugMode.Areas) { goto IL_A9; } result = AstarColor.GetAreaColor(node.Area); flag = true; goto IL_A9; case GraphDebugMode.Tags: result = AstarMath.IntToColor((int)node.Tag, 0.5f); flag = true; goto IL_A9; } goto IL_33; IL_A9: if (!flag) { if (data == null) { return(AstarColor.NodeConnection); } PathNode pathNode = data.GetPathNode(node); switch (AstarPath.active.debugMode) { case GraphDebugMode.G: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.G - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.H: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.H - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.F: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.F - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; } } result.a *= 0.5f; return(result); }
public Vector3 Raycast(Vector3 origin, out RaycastHit hit, out bool walkable) { walkable = true; if (!this.heightCheck || this.use2D) { hit = default(RaycastHit); return(origin - this.up * this.fromHeight); } if (this.thickRaycast) { Ray ray = new Ray(origin, -this.up); if (Physics.SphereCast(ray, this.finalRaycastRadius, out hit, this.fromHeight + 0.005f, this.heightMask)) { return(AstarMath.NearestPoint(ray.origin, ray.origin + ray.direction, hit.point)); } walkable &= !this.unwalkableWhenNoGround; } else { if (Physics.Raycast(origin, -this.up, out hit, this.fromHeight + 0.005f, this.heightMask)) { return(hit.point); } walkable &= !this.unwalkableWhenNoGround; } return(origin - this.up * this.fromHeight); }
private void DrawGizmoBezier(Vector3 p1, Vector3 p2) { Vector3 dir = p2 - p1; if (dir == Vector3.zero) { return; } Vector3 normal = Vector3.Cross(Vector3.up, dir); Vector3 normalUp = Vector3.Cross(dir, normal); normalUp = normalUp.normalized; normalUp *= dir.magnitude * 0.1f; Vector3 p1c = p1 + normalUp; Vector3 p2c = p2 + normalUp; Vector3 prev = p1; for (int i = 1; i <= 20; i++) { float t = i / 20.0f; Vector3 p = AstarMath.CubicBezier(p1, p1c, p2c, p2, t); Gizmos.DrawLine(prev, p); prev = p; } }
/** Returns the position with the correct height. * If #heightCheck is false, this will return \a position.\n * \a walkable will be set to false if nothing was hit. * The ray will check a tiny bit further than to the grids base to avoid floating point errors when the ground is exactly at the base of the grid */ public Vector3 CheckHeight(Vector3 position, out RaycastHit hit, out bool walkable) { walkable = true; if (!heightCheck || use2D) { hit = new RaycastHit(); return(position); } if (thickRaycast) { var ray = new Ray(position + up * fromHeight, -up); if (Physics.SphereCast(ray, finalRaycastRadius, out hit, fromHeight + 0.005F, heightMask)) { return(AstarMath.NearestPoint(ray.origin, ray.origin + ray.direction, hit.point)); } walkable &= unwalkableWhenNoGround; } else { // Cast a ray from above downwards to try to find the ground if (Physics.Raycast(position + up * fromHeight, -up, out hit, fromHeight + 0.005F, heightMask)) { return(hit.point); } walkable &= unwalkableWhenNoGround; } return(position); }
/** Same as #CheckHeight, except that the raycast will always start exactly at \a origin. * \a walkable will be set to false if nothing was hit. * The ray will check a tiny bit further than to the grids base to avoid floating point errors when the ground is exactly at the base of the grid */ public Vector3 Raycast(Vector3 origin, out RaycastHit hit, out bool walkable) { walkable = true; if (!heightCheck || use2D) { hit = new RaycastHit(); return(origin - up * fromHeight); } if (thickRaycast) { var ray = new Ray(origin, -up); if (Physics.SphereCast(ray, finalRaycastRadius, out hit, fromHeight + 0.005F, heightMask)) { return(AstarMath.NearestPoint(ray.origin, ray.origin + ray.direction, hit.point)); } walkable &= unwalkableWhenNoGround; } else { if (Physics.Raycast(origin, -up, out hit, fromHeight + 0.005F, heightMask)) { return(hit.point); } walkable &= unwalkableWhenNoGround; } return(origin - up * fromHeight); }
public static void PrintResults() { TimeSpan timeSpan = DateTime.UtcNow - AstarProfiler.startTime; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("============================\n\t\t\t\tProfile results:\n============================\n"); int num = 5; foreach (KeyValuePair <string, AstarProfiler.ProfilePoint> current in AstarProfiler.profiles) { num = Math.Max(current.Key.Length, num); } stringBuilder.Append(" Name ".PadRight(num)).Append("|").Append(" Total Time\t".PadRight(20)).Append("|").Append(" Total Calls ".PadRight(20)).Append("|").Append(" Avg/Call ".PadRight(20)); foreach (KeyValuePair <string, AstarProfiler.ProfilePoint> current2 in AstarProfiler.profiles) { double totalMilliseconds = current2.Value.watch.Elapsed.TotalMilliseconds; int totalCalls = current2.Value.totalCalls; if (totalCalls >= 1) { string key = current2.Key; stringBuilder.Append("\n").Append(key.PadRight(num)).Append("| "); stringBuilder.Append(totalMilliseconds.ToString("0.0").PadRight(20)).Append("| "); stringBuilder.Append(totalCalls.ToString().PadRight(20)).Append("| "); stringBuilder.Append((totalMilliseconds / (double)totalCalls).ToString("0.000").PadRight(20)); stringBuilder.Append(AstarMath.FormatBytesBinary((int)current2.Value.totalBytes).PadLeft(10)); } } stringBuilder.Append("\n\n============================\n\t\tTotal runtime: "); stringBuilder.Append(timeSpan.TotalSeconds.ToString("F3")); stringBuilder.Append(" seconds\n============================"); Debug.Log(stringBuilder.ToString()); }
//Movement stuff /** Returns in which direction to move from a point on the path. * A simple and quite slow (well, compared to more optimized algorithms) algorithm first finds the closest path segment (from #vectorPath) and then returns * the direction to the next point from there. The direction is not normalized. * \returns Direction to move from a \a point, returns Vector3.zero if #vectorPath is null or has a length of 0 */ public Vector3 GetMovementVector(Vector3 point) { if (vectorPath == null || vectorPath.Count == 0) { return(Vector3.zero); } if (vectorPath.Count == 1) { return(vectorPath[0] - point); } float minDist = float.PositiveInfinity; //Mathf.Infinity; int minSegment = 0; for (int i = 0; i < vectorPath.Count - 1; i++) { Vector3 closest = AstarMath.NearestPointStrict(vectorPath[i], vectorPath[i + 1], point); float dist = (closest - point).sqrMagnitude; if (dist < minDist) { minDist = dist; minSegment = i; } } return(vectorPath[minSegment + 1] - point); }
public Vector3 CheckHeight(Vector3 position, out RaycastHit hit, out bool walkable) { walkable = true; if (!this.heightCheck || this.use2D) { hit = default(RaycastHit); return(position); } if (this.thickRaycast) { Ray ray; ray..ctor(position + this.up * this.fromHeight, -this.up); if (Physics.SphereCast(ray, this.finalRaycastRadius, ref hit, this.fromHeight + 0.005f, this.heightMask)) { return(AstarMath.NearestPoint(ray.origin, ray.origin + ray.direction, hit.point)); } if (this.unwalkableWhenNoGround) { walkable = false; } } else { if (Physics.Raycast(position + this.up * this.fromHeight, -this.up, ref hit, this.fromHeight + 0.005f, this.heightMask)) { return(hit.point); } if (this.unwalkableWhenNoGround) { walkable = false; } } return(position); }
public static void PrintResults() { TimeSpan span = (TimeSpan)(DateTime.UtcNow - startTime); StringBuilder builder = new StringBuilder(); builder.Append("============================\n\t\t\t\tProfile results:\n============================\n"); int num = 5; foreach (KeyValuePair <string, ProfilePoint> pair in profiles) { num = Math.Max(pair.Key.Length, num); } builder.Append(" Name ".PadRight(num)).Append("|").Append(" Total Time\t".PadRight(20)).Append("|").Append(" Total Calls ".PadRight(20)).Append("|").Append(" Avg/Call ".PadRight(20)); foreach (KeyValuePair <string, ProfilePoint> pair2 in profiles) { double totalMilliseconds = pair2.Value.watch.Elapsed.TotalMilliseconds; int totalCalls = pair2.Value.totalCalls; if (totalCalls >= 1) { string key = pair2.Key; builder.Append("\n").Append(key.PadRight(num)).Append("| "); builder.Append(totalMilliseconds.ToString("0.0").PadRight(20)).Append("| "); builder.Append(totalCalls.ToString().PadRight(20)).Append("| "); double num4 = totalMilliseconds / ((double)totalCalls); builder.Append(num4.ToString("0.000").PadRight(20)); builder.Append(AstarMath.FormatBytesBinary((int)pair2.Value.totalBytes).PadLeft(10)); } } builder.Append("\n\n============================\n\t\tTotal runtime: "); builder.Append(span.TotalSeconds.ToString("F3")); builder.Append(" seconds\n============================"); UnityEngine.Debug.Log(builder.ToString()); }
public static Color GetAreaColor(uint area) { if (AstarColor.AreaColors == null || (ulong)area >= (ulong)((long)AstarColor.AreaColors.Length)) { return(AstarMath.IntToColor((int)area, 1f)); } return(AstarColor.AreaColors[(int)area]); }
public static Color GetAreaColor(uint area) { if ((AreaColors != null) && (area < AreaColors.Length)) { return(AreaColors[area]); } return(AstarMath.IntToColor((int)area, 1f)); }
/** Returns an color for an area, uses both user set ones and calculated. * If the user has set a color for the area, it is used, but otherwise the color is calculated using Mathfx.IntToColor * \see #AreaColors */ public static Color GetAreaColor(uint area) { if (AreaColors == null || area >= AreaColors.Length) { return(AstarMath.IntToColor((int)area, 1F)); } return(AreaColors[(int)area]); }
public static Color IntToColor(int i, float a) { int num = AstarMath.Bit(i, 1) + AstarMath.Bit(i, 3) * 2 + 1; int num2 = AstarMath.Bit(i, 2) + AstarMath.Bit(i, 4) * 2 + 1; int num3 = AstarMath.Bit(i, 0) + AstarMath.Bit(i, 5) * 2 + 1; return(new Color((float)num * 0.25f, (float)num2 * 0.25f, (float)num3 * 0.25f, a)); }
public static float DistancePointSegment2(int x, int z, int px, int pz, int qx, int qz) { Vector3 p = new Vector3((float)x, 0f, (float)z); Vector3 a = new Vector3((float)px, 0f, (float)pz); Vector3 b = new Vector3((float)qx, 0f, (float)qz); return(AstarMath.DistancePointSegment2(a, b, p)); }
public static void PrintResults() { TimeSpan endTime = DateTime.UtcNow - startTime; var output = new System.Text.StringBuilder(); output.Append("============================\n\t\t\t\tProfile results:\n============================\n"); int maxLength = 5; foreach (KeyValuePair <string, ProfilePoint> pair in profiles) { maxLength = Math.Max(pair.Key.Length, maxLength); } output.Append(" Name ".PadRight(maxLength)). Append("|").Append(" Total Time ".PadRight(20)). Append("|").Append(" Total Calls ".PadRight(20)). Append("|").Append(" Avg/Call ".PadRight(20)); foreach (var pair in profiles) { double totalTime = pair.Value.watch.Elapsed.TotalMilliseconds; int totalCalls = pair.Value.totalCalls; if (totalCalls < 1) { continue; } string name = pair.Key; output.Append("\n").Append(name.PadRight(maxLength)).Append("| "); output.Append(totalTime.ToString("0.0").PadRight(20)).Append("| "); output.Append(totalCalls.ToString().PadRight(20)).Append("| "); output.Append((totalTime / totalCalls).ToString("0.000").PadRight(20)); output.Append(AstarMath.FormatBytesBinary((int)pair.Value.totalBytes).PadLeft(10)); /*output.Append("\nProfile "); * output.Append(pair.Key); * output.Append(" took "); * output.Append(totalTime.ToString("0")); * output.Append(" ms to complete over "); * output.Append(totalCalls); * output.Append(" iteration"); * if (totalCalls != 1) output.Append("s"); * output.Append(", averaging "); * output.Append((totalTime / totalCalls).ToString("0.0")); * output.Append(" ms per call");*/ } output.Append("\n\n============================\n\t\tTotal runtime: "); output.Append(endTime.TotalSeconds.ToString("F3")); output.Append(" seconds\n============================"); Debug.Log(output.ToString()); }
public List <Vector3> SmoothBezier(List <Vector3> path) { if (subdivisions < 0) { subdivisions = 0; } int subMult = 1 << subdivisions; List <Vector3> subdivided = ListPool <Vector3> .Claim(); //new Vector3[(path.Length-1)*(int)subMult+1]; for (int i = 0; i < path.Count - 1; i++) { Vector3 tangent1 = Vector3.zero; Vector3 tangent2 = Vector3.zero; if (i == 0) { tangent1 = path[i + 1] - path[i]; } else { tangent1 = path[i + 1] - path[i - 1]; } if (i == path.Count - 2) { tangent2 = path[i] - path[i + 1]; } else { tangent2 = path[i] - path[i + 2]; } tangent1 *= bezierTangentLength; tangent2 *= bezierTangentLength; Vector3 v1 = path[i]; Vector3 v2 = v1 + tangent1; Vector3 v4 = path[i + 1]; Vector3 v3 = v4 + tangent2; for (int j = 0; j < subMult; j++) { subdivided.Add(AstarMath.CubicBezier(v1, v2, v3, v4, (float)j / subMult)); } } //Assign the last point subdivided.Add(path[path.Count - 1]); return(subdivided); }
public virtual Color NodeColor(GraphNode node, PathHandler data) { Color result = AstarColor.NodeConnection; GraphDebugMode debugMode = AstarPath.active.debugMode; switch (debugMode) { case GraphDebugMode.Penalty: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (node.Penalty - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); goto IL_18C; case GraphDebugMode.Connections: { IL_25: if (debugMode == GraphDebugMode.Areas) { result = AstarColor.GetAreaColor(node.Area); goto IL_18C; } if (data == null) { return(AstarColor.NodeConnection); } PathNode pathNode = data.GetPathNode(node); switch (AstarPath.active.debugMode) { case GraphDebugMode.G: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.G - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.H: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.H - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.F: result = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (pathNode.F - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; } goto IL_18C; } case GraphDebugMode.Tags: result = AstarMath.IntToColor((int)node.Tag, 0.5f); goto IL_18C; } goto IL_25; IL_18C: result.a *= 0.5f; return(result); }
/* Color to use for gizmos. * Returns a color to be used for the specified node with the current debug settings (editor only). * * \version Since 3.6.1 this method will not handle null nodes */ public virtual Color NodeColor(GraphNode node, PathHandler data) { #if !PhotonImplementation Color c = AstarColor.NodeConnection; switch (AstarPath.active.debugMode) { case GraphDebugMode.Areas: c = AstarColor.GetAreaColor(node.Area); break; case GraphDebugMode.Penalty: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, ((float)node.Penalty - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.Tags: c = AstarMath.IntToColor((int)node.Tag, 0.5F); break; default: if (data == null) { return(AstarColor.NodeConnection); } PathNode nodeR = data.GetPathNode(node); switch (AstarPath.active.debugMode) { case GraphDebugMode.G: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, ((float)nodeR.G - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.H: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, ((float)nodeR.H - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; case GraphDebugMode.F: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, ((float)nodeR.F - AstarPath.active.debugFloor) / (AstarPath.active.debugRoof - AstarPath.active.debugFloor)); break; } break; } c.a *= 0.5F; return(c); #else return(new Color(1, 1, 1)); #endif }
public static void Log() { System.Text.StringBuilder output = new System.Text.StringBuilder(); output.Append("============================\n\t\t\t\tSize Profile results:\n============================\n"); //foreach(KeyValuePair<string, ProfilePoint> pair in profiles) foreach (KeyValuePair <string, ProfileSizePoint> pair in profiles) { output.Append(pair.Key); output.Append(" used "); output.Append(AstarMath.FormatBytes((int)pair.Value.totalSize)); output.Append("\n"); } Debug.Log(output.ToString()); }
public static void SimplifyPath3(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint, int depth = 0) { if (start == end) { result.Add(nodes[start]); return; } if (start + 1 == end) { result.Add(nodes[start]); result.Add(nodes[end]); return; } int count = result.Count; GraphHitInfo graphHitInfo; if (rcg.Linecast(startPoint, endPoint, nodes[start], out graphHitInfo, result) || result[result.Count - 1] != nodes[end]) { result.RemoveRange(count, result.Count - count); int num = 0; float num2 = 0f; for (int i = start + 1; i < end - 1; i++) { float num3 = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (num3 > num2) { num = i; num2 = num3; } } int num4 = (num + start) / 2; int num5 = (num + end) / 2; if (num4 == num5) { RichFunnel.SimplifyPath3(rcg, nodes, start, num4, result, startPoint, (Vector3)nodes[num4].position, 0); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num4, end, result, (Vector3)nodes[num4].position, endPoint, depth + 1); } else { RichFunnel.SimplifyPath3(rcg, nodes, start, num4, result, startPoint, (Vector3)nodes[num4].position, depth + 1); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num4, num5, result, (Vector3)nodes[num4].position, (Vector3)nodes[num5].position, depth + 1); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num5, end, result, (Vector3)nodes[num5].position, endPoint, depth + 1); } } }
private void OnDrawGizmos(int boxi, int depth) { BBTree.BBTreeBox bBTreeBox = this.arr[boxi]; Vector3 a = new Vector3(bBTreeBox.rect.xMin, 0f, bBTreeBox.rect.yMin); Vector3 vector = new Vector3(bBTreeBox.rect.xMax, 0f, bBTreeBox.rect.yMax); Vector3 vector2 = (a + vector) * 0.5f; Vector3 size = (vector - vector2) * 2f; vector2.y += (float)depth * 0.2f; Gizmos.color = AstarMath.IntToColor(depth, 0.05f); Gizmos.DrawCube(vector2, size); if (bBTreeBox.node == null) { this.OnDrawGizmos(bBTreeBox.left, depth + 1); this.OnDrawGizmos(bBTreeBox.right, depth + 1); } }
private void OnDrawGizmos(int boxi, int depth) { BBTreeBox box = this.arr[boxi]; Vector3 vector = new Vector3(box.rect.xMin, 0f, box.rect.yMin); Vector3 vector2 = new Vector3(box.rect.xMax, 0f, box.rect.yMax); Vector3 center = (Vector3)((vector + vector2) * 0.5f); Vector3 size = (Vector3)((vector2 - center) * 2f); center.y += depth * 0.2f; Gizmos.color = AstarMath.IntToColor(depth, 0.05f); Gizmos.DrawCube(center, size); if (box.node == null) { this.OnDrawGizmos(box.left, depth + 1); this.OnDrawGizmos(box.right, depth + 1); } }
private void OnDrawGizmos(int boxi, int depth) { BBTree.BBTreeBox bbtreeBox = this.tree[boxi]; Vector3 a = (Vector3) new Int3(bbtreeBox.rect.xmin, 0, bbtreeBox.rect.ymin); Vector3 vector = (Vector3) new Int3(bbtreeBox.rect.xmax, 0, bbtreeBox.rect.ymax); Vector3 vector2 = (a + vector) * 0.5f; Vector3 size = (vector - vector2) * 2f; size = new Vector3(size.x, 1f, size.z); vector2.y += (float)(depth * 2); Gizmos.color = AstarMath.IntToColor(depth, 1f); Gizmos.DrawCube(vector2, size); if (!bbtreeBox.IsLeaf) { this.OnDrawGizmos(bbtreeBox.left, depth + 1); this.OnDrawGizmos(bbtreeBox.right, depth + 1); } }
private void OnDrawGizmos(int boxi, int depth) { BBTreeBox box = this.arr[boxi]; Vector3 vector = (Vector3) new Int3(box.rect.xmin, 0, box.rect.ymin); Vector3 vector2 = (Vector3) new Int3(box.rect.xmax, 0, box.rect.ymax); Vector3 center = (Vector3)((vector + vector2) * 0.5f); Vector3 size = (Vector3)((vector2 - center) * 2f); size = new Vector3(size.x, 1f, size.z); center.y += depth * 2; Gizmos.color = AstarMath.IntToColor(depth, 1f); Gizmos.DrawCube(center, size); if (box.node == null) { this.OnDrawGizmos(box.left, depth + 1); this.OnDrawGizmos(box.right, depth + 1); } }