//Create objects to make a visual representation of the maze. public void drawMaze() { wallDataHolder.Clear(); wallWorldHolder = new GameObject(); fullMaze = new GameObject(); wallData wd; foreach (mazeCell c in maze) { //Check to make sure there isn't a gamobject already created. if (c.wallLeft && !c.goWallLeft) { wd = new wallData() { position = new Vector2(c.gridPos.x - 0.5f, c.gridPos.y), isHorizontal = true }; createWall(wd, c, direction.RIGHT); } if (c.wallRight && !c.goWallRight) { wd = new wallData() { position = new Vector2(c.gridPos.x + 0.5f, c.gridPos.y), isHorizontal = true }; createWall(wd, c, direction.LEFT); } if (c.wallUp && !c.goWallUp) { wd = new wallData() { position = new Vector2(c.gridPos.x, c.gridPos.y + 0.5f), isHorizontal = false }; createWall(wd, c, direction.DOWN); } if (c.wallDown && !c.goWallDown) { wd = new wallData() { position = new Vector2(c.gridPos.x, c.gridPos.y - 0.5f), isHorizontal = false }; createWall(wd, c, direction.UP); } } floorWorldHolder = GameObject.CreatePrimitive(PrimitiveType.Quad); floorWorldHolder.GetComponent<Renderer>().material = _stats.floorMat; floorWorldHolder.transform.position = new Vector3((_stats.mazeDepth / 2.0f) + 0.5f, 0, (_stats.mazeWidth / 2.0f) + 0.5f); floorWorldHolder.transform.localScale = new Vector3(_stats.mazeDepth, _stats.mazeWidth, 1); floorWorldHolder.transform.Rotate(new Vector3(90, 0, 0)); floorWorldHolder.name = "Floor"; wallWorldHolder.transform.parent = fullMaze.transform; floorWorldHolder.transform.parent = fullMaze.transform; fullMaze.name = "Maze"; fullMaze.transform.localScale *= 10; }
//Create the wall object in the scene private void createWall(wallData wd, mazeCell _cell, direction _cellDir) { if (!wallDataHolder.Contains(wd)) { GameObject wallObject; wallDataHolder.Add(wd); wallObject = GameObject.CreatePrimitive(PrimitiveType.Cube); wallObject.GetComponent<Renderer>().material = _stats.wallMat; wallObject.name = ("Wall " + wd.position.x + ", " + wd.position.y); wallObject.transform.position = new Vector3(wd.position.x, _stats.wallHeight / 2, wd.position.y); if (wd.isHorizontal) { wallObject.transform.localScale = new Vector3(_stats.wallThickness, _stats.wallHeight, 1 + _stats.wallThickness); } else { wallObject.transform.localScale = new Vector3(1 + _stats.wallThickness, _stats.wallHeight, _stats.wallThickness); } wallObject.transform.parent = wallWorldHolder.transform; wallWorldHolder.name = "Walls"; switch (_cellDir) { case direction.LEFT: _cell.goWallRight = wallObject; if (returnCellInDir(_cell, direction.RIGHT) != _cell) { returnCellInDir(_cell, direction.RIGHT).goWallLeft = wallObject; } break; case direction.RIGHT: _cell.goWallLeft = wallObject; if (returnCellInDir(_cell, direction.LEFT) != _cell) { returnCellInDir(_cell, direction.LEFT).goWallRight = wallObject; } break; case direction.UP: _cell.goWallDown = wallObject; if (returnCellInDir(_cell, direction.DOWN) != _cell) { returnCellInDir(_cell, direction.DOWN).goWallUp = wallObject; } break; case direction.DOWN: _cell.goWallUp = wallObject; if (returnCellInDir(_cell, direction.UP) != _cell) { returnCellInDir(_cell, direction.UP).goWallDown = wallObject; } break; } } }