public void OnDrawGizmos(RetainedGizmos gizmos) { var hasher = new RetainedGizmos.Hasher(AstarPath.active); hasher.AddHash(gizmoVersion); if (!gizmos.Draw(hasher)) { var builder = ObjectPool <RetainedGizmos.Builder> .Claim(); var centers = ArrayPool <Vector3> .Claim(areas.Length); for (var i = 0; i < areas.Length; i++) { var center = Int3.zero; var childs = children[i]; if (childs.Count > 0) { for (var j = 0; j < childs.Count; j++) { center += childs[j].position; } center /= childs.Count; centers[i] = (Vector3)center; } } for (var i = 0; i < areas.Length; i++) { if (children[i].Count > 0) { for (var j = 0; j < connections[i].Count; j++) { if (connections[i][j] > i) { builder.DrawLine(centers[i], centers[connections[i][j]], Color.black); } } } } builder.Submit(gizmos, hasher); } }
void OnDrawGizmos() { // Prevent interfering with scene view picking if (Event.current.type != EventType.Repaint) { return; } if (drawObstacles && simulator != null && simulator.obstacles != null) { var hasher = new RetainedGizmos.Hasher(); var obstacles = simulator.obstacles; int numEdges = 0; for (int i = 0; i < obstacles.Count; i++) { var vertex = obstacles[i]; do { hasher.AddHash(vertex.position.GetHashCode() ^ vertex.height.GetHashCode()); numEdges++; vertex = vertex.next; } while (vertex != obstacles[i] && vertex != null); } if (!gizmos.Draw(hasher)) { Profiler.BeginSample("Rebuild RVO Obstacle Gizmos"); using (var helper = gizmos.GetGizmoHelper(null, hasher)) { var up = movementPlane == MovementPlane.XY ? Vector3.back : Vector3.up; var vertices = new Vector3[numEdges * 6]; var colors = new Color[numEdges * 6]; int edgeIndex = 0; for (int i = 0; i < obstacles.Count; i++) { var start = obstacles[i]; var c = start; do { vertices[edgeIndex * 6 + 0] = c.position; vertices[edgeIndex * 6 + 1] = c.next.position; vertices[edgeIndex * 6 + 2] = c.next.position + up * c.next.height; vertices[edgeIndex * 6 + 3] = c.position; vertices[edgeIndex * 6 + 4] = c.next.position + up * c.next.height; vertices[edgeIndex * 6 + 5] = c.position + up * c.height; edgeIndex++; c = c.next; } while (c != start && c != null && c.next != null); } for (int i = 0; i < colors.Length; i++) { colors[i] = ObstacleColor; } helper.DrawTriangles(vertices, colors, numEdges * 2); } Profiler.EndSample(); } gizmos.FinalizeDraw(); } }
public static void OnDrawGizmos(this NavmeshBase navmeshBase, Pathfinding.Util.RetainedGizmos gizmos, bool drawNodes) { if (!drawNodes) { return; } using (var helper = gizmos.GetSingleFrameGizmoHelper()) { var bounds = new Bounds(); bounds.SetMinMax(Vector3.zero, navmeshBase.forcedBoundsSize); // Draw a write cube using the latest transform // (this makes the bounds update immediately if some field is changed in the editor) helper.builder.DrawWireCube(navmeshBase.CalculateTransform(), bounds, Color.white); } if (navmeshBase.tiles != null) { // Update navmesh vizualizations for // the tiles that have been changed for (int i = 0; i < navmeshBase.tiles.Length; i++) { // This may happen if an exception has been thrown when the graph was scanned. // We don't want the gizmo code to start to throw exceptions as well then as // that would obscure the actual source of the error. if (navmeshBase.tiles[i] == null) { continue; } // Calculate a hash of the tile var hasher = new RetainedGizmos.Hasher(AstarPath.active); hasher.AddHash(navmeshBase.showMeshOutline ? 1 : 0); hasher.AddHash(navmeshBase.showMeshSurface ? 1 : 0); hasher.AddHash(navmeshBase.showNodeConnections ? 1 : 0); var nodes = navmeshBase.tiles[i].nodes; for (int j = 0; j < nodes.Length; j++) { hasher.HashNode(nodes[j]); } if (!gizmos.Draw(hasher)) { using (var helper = gizmos.GetGizmoHelper(hasher)) { if (navmeshBase.showMeshSurface || navmeshBase.showMeshOutline) { navmeshBase.CreateNavmeshSurfaceVisualization(navmeshBase.tiles[i], helper); } if (navmeshBase.showMeshSurface || navmeshBase.showMeshOutline) { CreateNavmeshOutlineVisualization(navmeshBase.tiles[i], helper); } if (navmeshBase.showNodeConnections) { for (int j = 0; j < nodes.Length; j++) { helper.DrawConnections(nodes[j]); } } } } gizmos.Draw(hasher); } } if (AstarPath.active.showUnwalkableNodes) { navmeshBase.DrawUnwalkableNodes(AstarPath.active.unwalkableNodeDebugSize); } }