// 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(); }
void SetCurrentTile(SpriteTile tile) { // Deselect our current tile if (_currentTile != null) { _currentTile.SetHighlighted(false); } if (tile != null) { tile.SetHighlighted(true); if (_selectionBox != null) { // Activate the selection box _selectionBox.SetActive(true); // Set the selection slightly in front of the tile Vector3 pos = tile.transform.position; pos.z -= 0.01f; _selectionBox.transform.position = pos; // Set the selection to the same size as the tiles grid node _selectionBox.transform.localScale = tile.gridNode.size / _selectionBoxRenderer.sprite.bounds.size; } } else { // We're not selecting anything. Disable the selection box if (_selectionBox != null) { _selectionBox.SetActive(false); } } _currentTile = tile; }