An ALINE Gizmo the PolarGraphGenerator example

Here is a simple ALINE gizmo component for the PolraGraphGenerator example in the docs. Place the component on or below the Astar GameObject

using UnityEngine;
using Drawing;

public class PolarGraphGizmo : MonoBehaviourGizmos {
//If this component is on or below the GameObject with AstarPath on it in the hierarchy
// it will find AstarPath, if it is else where the value can be set in the inspector.
public AstarPath aStarPath;

public override void DrawGizmos () {
    aStarPath ??= GetComponentInParent<AstarPath>();
    if (!aStarPath.showGraphs) {
        return;
    }
    foreach (var graph in aStarPath.graphs) {
        if (!(graph is PolarGraph) || !graph.drawGizmos || graph.CountNodes() == 0) {
            continue;
        }
        var polarGraph = (PolarGraph) graph;
        //The PolarGraph is a point graph laid out in like a spider web
        //this code will also work on any simple point graph
        using (Draw.WithColor(Color.white)) {
            foreach (var node in polarGraph.nodes) {
                foreach (var connection in node.connections) {
                    Draw.Line((Vector3) node.position, (Vector3) connection.node.position);
                }
            }
        }
    }
}

}

Hi

A more idiomatic approach would be to override the OnDrawGizmos method in the PolarGraphGenerator class:

public override void OnDrawGizmos(DrawingData gizmos, bool drawNodes, RedrawScope redrawScope)
{
	var draw = gizmos.GetBuilder(redrawScope);
	if (nodes != null && drawNodes) {
		using (draw.WithColor(Color.white)) {
			foreach (var node in nodes) {
				foreach (var connection in node.connections) {
					draw.Line((Vector3) node.position, (Vector3) connection.node.position);
				}
			}
		}
	}
	draw.Dispose();
}

Thanks, that is a much cleaner implementation.