/** Draw gizmos for the graph */ public virtual void OnDrawGizmos(RetainedGizmos gizmos, bool drawNodes) { 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 RetainedGizmos.Hasher(active); GetNodes(node => hasher.HashNode(node)); // Update the gizmo mesh if necessary if (!gizmos.Draw(hasher)) { using (var helper = gizmos.GetGizmoHelper(active, hasher)) { GetNodes((System.Action <GraphNode>)helper.DrawConnections); } } if (active.showUnwalkableNodes) { DrawUnwalkableNodes(active.unwalkableNodeDebugSize); } }
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); } }
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); } }