public VoronoiSpawnGenerator(Vector3[] playerSpawns, float minSpacing, float maxDrift, float maxX, float maxZ) { this.minSpacing = minSpacing; this.playerSpawns = playerSpawns; this.maxDrift = maxDrift; this.maxX = maxX; this.maxZ = maxZ; // build site list, translating x,z to x,y var sites = new Vector2[playerSpawns.Length]; for (var i = 0; i < playerSpawns.Length; i++) { sites[i] = new Vector2(playerSpawns[i].x, playerSpawns[i].z); } var size = new Vector3(maxX, maxZ, 0); var bounds = new Bounds(size / 2f, size); this.voronoi = new Voronoi(bounds, sites); voronoi.Compute(); for (var i = 0; i < voronoi.edgeList.Count; i++) { var edge = voronoi.edgeList[i]; Debug.DrawLine( new Vector3(edge.vertices[0].x, 100, edge.vertices[0].y), new Vector3(edge.vertices[1].x, 100, edge.vertices[1].y), Color.red, 300); } }
public VoronoiBisectorSpawnGenerator(Vector3[] playerSpawns, float maxX, float maxZ) { // build site list, translating x,z to x,y var sites = new Vector2[playerSpawns.Length]; for (var i = 0; i < playerSpawns.Length; i++) { sites[i] = new Vector2(playerSpawns[i].x, playerSpawns[i].z); } var size = new Vector3(maxX, maxZ, 0); var bounds = new Bounds(size / 2f, size); this.voronoi = new Voronoi(bounds, sites); voronoi.Compute(); }