Пример #1
0
 public void SpawnMaze()
 {
     for (int level = 0; level < AmountOfCellsInRow; level++)
     {
         _mazeGenerator           = new RecursiveMazeGenerator(AmountOfCellsInRow, AmountOfCellsInRow);
         _mazeGenerator.GoalCount = GoalCount;
         _mazeGenerator.GenerateMaze();
         _level = new GameObject($"Level {level + 1}");
         _level.transform.parent = transform;
         _floor = new List <GameObject>();
         _walls = new List <GameObject>();
         for (int row = 0; row < AmountOfCellsInRow; row++)
         {
             for (int column = 0; column < AmountOfCellsInRow; column++)
             {
                 CheckAndSpawnCell(row, column, level);
             }
         }
         if (_bakedObjectsList.Keys.Count > level * 2)
         {
             _bakedObjectsList.Clear();
         }
         _bakedObjectsList.Add($"Floor {level}", _floor);
         _bakedObjectsList.Add($"Walls {level}", _walls);
     }
 }
Пример #2
0
    private void Start()
    {
        var front = transform.Find("Front");
        var back  = transform.Find("Back");
        var left  = transform.Find("Left");
        var right = transform.Find("Right");
        var goals = 0;

        var mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns);

        mMazeGenerator.GenerateMaze();

        for (var row = 0; row < Rows; row++)
        {
            for (var column = 0; column < Columns; column++)
            {
                var x    = column * CellWidth;
                var z    = row * CellHeight;
                var cell = mMazeGenerator.GetMazeCell(row, column);
                var tmp  = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0));
                tmp.transform.parent = transform;
                var wall = WallFabs[Random.Range(0, WallFabs.Length)];
                if (cell.WallRight)
                {
                    tmp = Instantiate(wall, new Vector3(x + CellWidth / 2, 0, z), Quaternion.Euler(0, 90, 0));
                    tmp.transform.parent = right;
                }

                if (cell.WallFront)
                {
                    tmp = Instantiate(wall, new Vector3(x, 0, z + CellHeight / 2), Quaternion.Euler(0, 0, 0));
                    tmp.transform.parent = front;
                }

                if (cell.WallLeft)
                {
                    tmp = Instantiate(wall, new Vector3(x - CellWidth / 2, 0, z), Quaternion.Euler(0, 270, 0));
                    tmp.transform.parent = left;
                }

                if (cell.WallBack)
                {
                    tmp = Instantiate(wall, new Vector3(x, 0, z - CellHeight / 2), Quaternion.Euler(0, 180, 0));
                    tmp.transform.parent = back;
                }

                if (!cell.IsGoal || GoalPrefabs == null || GoalPrefabs.Length < 1)
                {
                    continue;
                }
                var goalPrefab = GoalPrefabs[Random.Range(0, GoalPrefabs.Length)];
                tmp = Instantiate(goalPrefab, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0));
                tmp.transform.parent = transform;
                goals++;
            }
        }

        Manager.SetRemaining(goals);
    }