// Clears all active tiles on the grid and re-initializes it with fresh randomized tiles from the tile pool. public void ResetGrid() { _grid.Clear(_tilePool); GameSettings.LevelSettings settings = GameSettings.currentLevelSettings; _grid.ResizeGrid(settings.gridSize.x + 2, settings.gridSize.y + 2); int tileCount = settings.gridSize.x * settings.gridSize.y; SpriteTileInfo[] tiles = GetRandomTilePairs(settings.uniqueTileCount, tileCount); // Fill the grid leaving cells around the border empty for (int x = 1; x < _grid.columns - 1; x++) { for (int y = 1; y < _grid.rows - 1; y++) { int i = (y - 1) * (_grid.columns - 2) + (x - 1); if (tiles[i] != null) { // Grab a new tile from the pool and initalize it SpriteTile tile = _tilePool.Pop(); tile.SetSpriteTileInfo(tiles[i]); tile.SetGridNode(_grid[x, y]); tile.SetHighlighted(false); tile.SetColliderEnabled(true); } } } // Make sure we haven't spawned a grid with an unwinnable pattern of tiles FixUnwinnables(); }