/// <summary>Draw gizmos for the graph</summary> public virtual void OnDrawGizmos(DrawingData gizmos, bool drawNodes, RedrawScope redrawScope) { if (!drawNodes) { return; } // This is a relatively slow default implementation. // subclasses of the base graph class may override // this method to draw gizmos in a more optimized way var hasher = new NodeHasher(active); GetNodes(node => hasher.HashNode(node)); // Update the gizmo mesh if necessary if (!gizmos.Draw(hasher, redrawScope)) { using (var helper = GraphGizmoHelper.GetGizmoHelper(gizmos, active, hasher, redrawScope)) { GetNodes((System.Action <GraphNode>)helper.DrawConnections); } } if (active.showUnwalkableNodes) { DrawUnwalkableNodes(gizmos, active.unwalkableNodeDebugSize, redrawScope); } }
// static Color ObstacleColor = new Color(255/255f, 60/255f, 15/255f, 1.0f); public override void DrawGizmos() { // Prevent interfering with scene view picking //if (Event.current.type != EventType.Repaint) return; #if FALSE if (drawObstacles && simulatorBurst != null && simulatorBurst.obstacles != null) { var hasher = DrawingData.Hasher.Create(this); var obstacles = simulatorBurst.obstacles; int numEdges = 0; for (int i = 0; i < obstacles.Count; i++) { var vertex = obstacles[i]; do { hasher.Add(vertex.position.GetHashCode() ^ vertex.height.GetHashCode()); numEdges++; vertex = vertex.next; } while (vertex != obstacles[i] && vertex != null); } if (!DrawingManager.instance.gizmos.Draw(hasher)) { Profiler.BeginSample("Rebuild RVO Obstacle Gizmos"); using (var helper = GraphGizmoHelper.GetGizmoHelper(DrawingManager.instance.gizmos, null, hasher, default)) { 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(); } } #endif }
private void RecalculateDebugLimits() { this.debugFloor = float.PositiveInfinity; this.debugRoof = float.NegativeInfinity; bool ignoreSearchTree = !this.showSearchTree || this.debugPathData == null; for (int i = 0; i < this.graphs.Length; i++) { if (this.graphs[i] != null && this.graphs[i].drawGizmos) { this.graphs[i].GetNodes(delegate(GraphNode node) { if (ignoreSearchTree || GraphGizmoHelper.InSearchTree(node, this.debugPathData, this.debugPathID)) { if (this.debugMode == GraphDebugMode.Penalty) { this.debugFloor = Mathf.Min(this.debugFloor, node.Penalty); this.debugRoof = Mathf.Max(this.debugRoof, node.Penalty); } else if (this.debugPathData != null) { PathNode pathNode = this.debugPathData.GetPathNode(node); GraphDebugMode graphDebugMode = this.debugMode; if (graphDebugMode != GraphDebugMode.F) { if (graphDebugMode != GraphDebugMode.G) { if (graphDebugMode == GraphDebugMode.H) { this.debugFloor = Mathf.Min(this.debugFloor, pathNode.H); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.H); } } else { this.debugFloor = Mathf.Min(this.debugFloor, pathNode.G); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.G); } } else { this.debugFloor = Mathf.Min(this.debugFloor, pathNode.F); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.F); } } } }); } } if (float.IsInfinity(this.debugFloor)) { this.debugFloor = 0f; this.debugRoof = 1f; } if (this.debugRoof - this.debugFloor < 1f) { this.debugRoof += 1f; } }
/** Creates an outline of the navmesh for use in OnDrawGizmos in the editor */ public static void CreateNavmeshOutlineVisualization(NavmeshTile tile, GraphGizmoHelper helper) { var sharedEdges = new bool[3]; for (int j = 0; j < tile.nodes.Length; j++) { sharedEdges[0] = sharedEdges[1] = sharedEdges[2] = false; var node = tile.nodes[j]; for (int c = 0; c < node.connections.Length; c++) { var other = node.connections[c].node as TriangleMeshNode; // Loop through neighbours to figure out which edges are shared if (other != null && other.GraphIndex == node.GraphIndex) { for (int v = 0; v < 3; v++) { for (int v2 = 0; v2 < 3; v2++) { if (node.GetVertexIndex(v) == other.GetVertexIndex((v2 + 1) % 3) && node.GetVertexIndex((v + 1) % 3) == other.GetVertexIndex(v2)) { // Found a shared edge with the other node sharedEdges[v] = true; v = 3; break; } } } } } var color = helper.NodeColor(node); for (int v = 0; v < 3; v++) { if (!sharedEdges[v]) { helper.builder.DrawLine((Vector3)node.GetVertex(v), (Vector3)node.GetVertex((v + 1) % 3), color); } } } }
public virtual void OnDrawGizmos(RetainedGizmos gizmos, bool drawNodes) { if (!drawNodes) { return; } RetainedGizmos.Hasher hasher = new RetainedGizmos.Hasher(this.active); this.GetNodes(delegate(GraphNode node) { hasher.HashNode(node); }); if (!gizmos.Draw(hasher)) { using (GraphGizmoHelper gizmoHelper = gizmos.GetGizmoHelper(this.active, hasher)) { this.GetNodes(new Action <GraphNode>(gizmoHelper.DrawConnections)); } } if (this.active.showUnwalkableNodes) { this.DrawUnwalkableNodes(this.active.unwalkableNodeDebugSize); } }
private void RecalculateDebugLimits() { this.debugFloor = float.PositiveInfinity; this.debugRoof = float.NegativeInfinity; bool ignoreSearchTree = !this.showSearchTree || this.debugPathData == null; Action <GraphNode> < > 9__0; for (int i = 0; i < this.graphs.Length; i++) { if (this.graphs[i] != null && this.graphs[i].drawGizmos) { NavGraph navGraph = this.graphs[i]; Action <GraphNode> action; if ((action = < > 9__0) == null) { action = (< > 9__0 = delegate(GraphNode node) { if (ignoreSearchTree || GraphGizmoHelper.InSearchTree(node, this.debugPathData, this.debugPathID)) { if (this.debugMode == GraphDebugMode.Penalty) { this.debugFloor = Mathf.Min(this.debugFloor, node.Penalty); this.debugRoof = Mathf.Max(this.debugRoof, node.Penalty); return; } if (this.debugPathData != null) { PathNode pathNode = this.debugPathData.GetPathNode(node); switch (this.debugMode) { case GraphDebugMode.G: this.debugFloor = Mathf.Min(this.debugFloor, pathNode.G); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.G); return; case GraphDebugMode.H: this.debugFloor = Mathf.Min(this.debugFloor, pathNode.H); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.H); break; case GraphDebugMode.F: this.debugFloor = Mathf.Min(this.debugFloor, pathNode.F); this.debugRoof = Mathf.Max(this.debugRoof, pathNode.F); return; default: return; } } } }); } navGraph.GetNodes(action); } } if (float.IsInfinity(this.debugFloor)) { this.debugFloor = 0f; this.debugRoof = 1f; } if (this.debugRoof - this.debugFloor < 1f) { this.debugRoof += 1f; } }
/** Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor */ public static void CreateNavmeshSurfaceVisualization(this NavmeshBase navmeshBase, NavmeshTile tile, GraphGizmoHelper helper) { // Vertex array might be a bit larger than necessary, but that's ok var vertices = PF.ArrayPool <Vector3> .Claim(tile.nodes.Length *3); var colors = PF.ArrayPool <Color> .Claim(tile.nodes.Length *3); for (int j = 0; j < tile.nodes.Length; j++) { var node = tile.nodes[j]; Int3 v0, v1, v2; node.GetVertices(out v0, out v1, out v2); vertices[j * 3 + 0] = (Vector3)v0; vertices[j * 3 + 1] = (Vector3)v1; vertices[j * 3 + 2] = (Vector3)v2; var color = helper.NodeColor(node); colors[j * 3 + 0] = colors[j * 3 + 1] = colors[j * 3 + 2] = color; } if (navmeshBase.showMeshSurface) { helper.DrawTriangles(vertices, colors, tile.nodes.Length); } if (navmeshBase.showMeshOutline) { helper.DrawWireTriangles(vertices, colors, tile.nodes.Length); } // Return lists to the pool PF.ArrayPool <Vector3> .Release(ref vertices); PF.ArrayPool <Color> .Release(ref colors); }