public static void GenerateSquares(Transform transform, bool useColumns, LevelPrefabs prefabs, GameObject squarePrefab, Vector3[,,] coordinates, MazeSquare[,,] squares) { for (int z = 0; z < squares.GetLength(2); z++) { GameObject layer = NewSection("Layer", z, transform); for (int i = 0; i < squares.GetLength(0); i++) { GameObject row = NewSection("Row", i, layer.transform); for (int j = 0; j < squares.GetLength(1); j++) { if (squares[i, j, z] == null) { continue; } MazeSurveyLogic.Survey(i, j, z, squares); #region Setup Square in Hierarchy squares[i, j, z].layout = BuildLayout(useColumns, prefabs, squarePrefab, squares[i, j, z].adjacents); GameObject sq = squares[i, j, z].layout; sq.transform.parent = transform; sq.transform.localPosition = coordinates[i, j, z]; sq.transform.parent = row.transform; sq.name = "Sq" + (j + 1); #endregion } } } }
public static void SetOutlet(bool useColumns, LevelPrefabs prefabs, GameObject outlet, out MazeSquare outletSq, MazeSquare[,,] squares) { List <MazeSquare> vacancyList = new List <MazeSquare>(); vacancyList = FillVacancyList(vacancyList, squares); int outletIndex = Random.Range(0, vacancyList.Count); MazeSquare square = vacancyList[outletIndex]; MazeSquare tempSq; //Identify and store the root square's open adjacent squares List <int> indices = new List <int>(); List <MazeSquare> openAdjacents = new List <MazeSquare>(); for (int i = 0; i < CORNERS; i++) { if (square.adjacents[i] == null) { openAdjacents.Add(square.adjacents[i]); indices.Add(i); } } int rand = Random.Range(0, openAdjacents.Count); MazeSurveyLogic.SurveyOutlet(square, indices[rand], squares, out tempSq); outletSq = tempSq; //Replace wall with outlet Transform wall = square.layout.transform.GetChild(indices[rand]); Object.Destroy(wall.GetChild(0).gameObject); outlet = Object.Instantiate(outlet, wall); ZeroOut(outlet); outletSq.layout = outlet; if (vacancyList.Count > 1) { vacancyList.RemoveAt(outletIndex); } }