5 public static class BoundsDivider
7 public static void Divide(Bounds bounds,
float edgeLength, out Vector3[] positions, out
int xDivisionCount,
8 out
int yDivisionCount,
9 out
int zDivisionCount)
12 GetMinMax(bounds, out min, out max);
13 var center = (min + max) / 2f;
15 if (edgeLength == 1.0f)
17 positions =
new Vector3[1];
18 positions[0] = center;
70 positions =
new Vector3[xDivisionCount * yDivisionCount * zDivisionCount];
72 for (var x = minX; x <= maxX; x += edgeLength)
73 for (var y = minY; y <= maxY; y += edgeLength)
74 for (var z = minZ; z <= maxZ; z += edgeLength)
76 positions[index] =
new Vector3(x, y, z);
81 static void GetMinMax(Bounds bounds, out Vector3 min, out Vector3 max)
83 var tmpMin = bounds.min;
84 var tmpMax = bounds.max;
85 var minZ = Mathf.Min(tmpMin.z, tmpMax.z);
86 var maxZ = Mathf.Max(tmpMin.z, tmpMax.z);