Shows a simple graph type generating a polar graph.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Pathfinding;
using Pathfinding.Serialization.JsonFx;
#if FALSE
[JsonOptIn]
public class PolarGraph : NavGraph {
[JsonMember]
public int circles = 10;
[JsonMember]
public int steps = 20;
[JsonMember]
public Vector3 center = Vector3.zero;
[JsonMember]
public float scale = 2;
public override void Scan () {
nodes = CreateNodes (circles*steps);
Matrix4x4 matrix = Matrix4x4.TRS (center,Quaternion.identity,Vector3.one*scale);
nodes[0].Position = (Int3)matrix.MultiplyPoint (Vector3.zero);
float anglesPerStep = (2*Mathf.PI)/steps;
for (int i=1;i<circles;i++) {
for (int j=0;j<steps;j++) {
float angle = j * anglesPerStep;
Vector3 pos = new Vector3 (Mathf.Sin (angle),0, Mathf.Cos (angle));
pos *= i*scale;
pos = matrix.MultiplyPoint (pos);
GraphNode node = nodes[(i-1)*steps + j + 1];
node.Position = (Int3)pos;
}
}
for (int i=1;i<circles;i++) {
for (int j=0;j<steps;j++) {
GraphNode node = nodes[(i-1)*steps + j + 1];
int numConnections = (i < circles-1) ? 4 : 3;
GraphNode[] connections = new GraphNode[numConnections];
int[] connectionCosts = new int[numConnections];
int connId = (i-1)*steps + (j < steps-1 ? j+1 : 0) + 1;
connections[0] = nodes[connId];
connId = (i-1)*steps + (j > 0 ? j-1 : steps-1) + 1;
connections[1] = nodes[connId];
if (i > 1) {
connId = (i-2)*steps + j + 1;
} else {
connId = 0;
}
connections[2] = nodes[connId];
if (numConnections == 4) {
connId = i*steps + j + 1;
connections[3] = nodes[connId];
}
for (int q=0;q<connections.Length;q++) {
connectionCosts[q] = (node.Position-connections[q].Position).costMagnitude;
}
node.connections = connections;
node.connectionCosts = connectionCosts;
}
}
GraphNode centerNode = nodes[0];
centerNode.connections = new GraphNode[steps];
centerNode.connectionCosts = new int[steps];
for (int j=0;j<steps;j++) {
centerNode.connections[j] = nodes[1+j];
centerNode.connectionCosts[j] = (centerNode.Position-centerNode.connections[j].position).costMagnitude;
}
for (int i=0;i<nodes.Length;i++) {
nodes[i].Walkable = true;
}
}
}
#endif