private IEnumerator <float> _SpawnLevelObjects(LevelObjectType[] levelObjectTypeContainer, Vector3 spawnOrigin) { int objectCount = levelObjectTypeContainer.Length; int gridWidth = ViewModel.GridWidth; // Number of objects per slot in X-axis float widthMultiplier = LevelWidth / ViewModel.GridWidth; float edge = widthMultiplier / 2.0f; // from center to "edge" of a slot, essentially half a slot float gridLeftStartPos = -LevelWidth / 2.0f + edge; // Start "Left" X-axis position of Slots LevelObjectSpawnData spawnData = new LevelObjectSpawnData(); spawnData.SetIndependentData(widthMultiplier, SlotWidth, edge); for (var i = 0; i < objectCount; i++) { spawnData.SetIndexDependentData(i, gridLeftStartPos, gridWidth, widthMultiplier); SpawnLevelObject(levelObjectTypeContainer[i], spawnOrigin, spawnData); yield return(0); } spawnData.SetEndBlockIndexDependentData(levelObjectTypeContainer.Length / gridWidth, widthMultiplier); SpawnLevelObject(LevelObjectType.EndLevelBlock, spawnOrigin, spawnData); }
private void SpawnLevelObject(LevelObjectType levelObjectType, Vector3 spawnOrigin, LevelObjectSpawnData sd) { switch (levelObjectType) { case LevelObjectType.Hay: case LevelObjectType.SuperHay: for (float xAdjust = sd.startAdjustment; xAdjust < sd.edge; xAdjust += sd.distanceBetween) { for (float zAdjust = sd.startAdjustment; zAdjust < sd.edge; zAdjust += sd.distanceBetween) { sd.positionModifications = new Vector3( sd.modifiedPositionIndex + xAdjust, 0, SpawnDistance + sd.modifiedHeight + zAdjust); CreateLevelObject(spawnOrigin, sd.positionModifications, levelObjectType, sd.objectIndex); } } break; case LevelObjectType.EndLevelBlock: sd.positionModifications = new Vector3( sd.modifiedPositionIndex, 0, SpawnDistance + sd.modifiedHeight + LevelEndBlockDistance); CreateLevelObject(spawnOrigin, sd.positionModifications, levelObjectType, sd.objectIndex); break; case LevelObjectType.Rock: sd.positionModifications = new Vector3( sd.modifiedPositionIndex, 0, SpawnDistance + sd.modifiedHeight); CreateLevelObject(spawnOrigin, sd.positionModifications, levelObjectType, sd.objectIndex); break; } }