SR Formation - Smehi/WaveOne GitHub Wiki
When object spawn they do so in formations. Even if the group size of that object is set to 1, the calculations just put them in the center. Currently there is only a single formation script which is the SquareFormation. This formation spawns object in a square, where it spreads in width (X-axis) first and then depth (Z-axis). It also spawns the object as close to eachother as possible. For formations there is a interface IFormation which says what methods it should contain.
List<Vector3> MakeFormation(GameObject gameObject, int groupSize)
We supply the method with a GameObject and a groupSize. The GameObject is used to get the bounds of the object so they don't spawn inside eachother. The size is used to get an even square where possible and otherwise favoring width. It will then make the formation and return a list of Vector3s representing the positions. These are all relative to Vector3.zero.
For example in your spawning script you would use the formation like so.
public IEnumerator WaveDeployment()
{
...
GameObject instance = null;
bool gotRelativeGroupPositions = false;
List<Vector3> relativeGroupPositions = new List<Vector3>();
// Loop for the amount of enemies we want to spawn.
for (int i = 0; i < spawnAmount; i++)
{
// Save a reference to the enemy we spawned.
instance = Instantiate(list[currentWave].enemies[enemyIndex].gameObject);
// We only want to get the formation positions once so we do a simple check.
if (!gotRelativeGroupPositions)
{
// We can only now get the positions because we need a GameObject
// that is active in the scene.
// Using a prefab object will result in bounds of zero.
// WaveConfigurator also has a reference to the FormationScript which you can use.
// Otherwise you could do GetComponent<IFormation>().MakeFormation(...).
relativeGroupPositions = waveConfig.FormationScript.MakeFormation(instance, spawnAmount);
gotRelativeGroupPositions = true;
}
// Now we can add the position for each enemy.
// Remember that the positions are relative to Vector3.zero so we
// need to add it to the original position.
instance.transform.position += relativeGroupPositions[i];
}
...
}