public IEnumerator GenerateGrid(bool replace) { yield return(new WaitForSeconds(1f)); for (int i = 0; i < grid.GetLength(1); i++) { for (int j = 0; j < grid.GetLength(0); j++) { if (replace && grid[j, i] != null) { continue; } grid[j, i] = CreateTile(j, i); if (j - 1 >= 0) { while (true) { Sc_Tile adjacentTile = grid[j - 1, i].GetComponent <Sc_Tile>(); Sc_Tile currentTile = grid[j, i].GetComponent <Sc_Tile>(); if (currentTile.IsSameOf(adjacentTile)) { Destroy(grid[j, i]); grid[j, i] = CreateTile(j, i); } else { break; } } } if (i - 1 >= 0) { while (true) { Sc_Tile adjacentTile = grid[j, i - 1].GetComponent <Sc_Tile>(); Sc_Tile currentTile = grid[j, i].GetComponent <Sc_Tile>(); if (currentTile.IsSameOf(adjacentTile)) { Destroy(grid[j, i]); grid[j, i] = CreateTile(j, i); } else { break; } } } Sc_Tile tile = grid[j, i].GetComponent <Sc_Tile>(); tile.Creation(); StartCoroutine(CheckThisTile(tile, 0.5f)); } } canSwap = true; Sc_EventManager.instance.onUpdateStats.Invoke(); }
List <Sc_Tile> CheckLine(Sc_Tile startTile, Vector2Int direction) { Vector2Int lastCoord = new Vector2Int(); bool outB = false; List <Sc_Tile> tempValidTiles = new List <Sc_Tile>(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { Vector2Int computeCoordinates = startTile.coordinates + (direction * i); bool inBound = computeCoordinates.x >= 0 && computeCoordinates.x < grid.GetLength(0) && computeCoordinates.y >= 0 && computeCoordinates.y < grid.GetLength(1); if (inBound && grid[computeCoordinates.x, computeCoordinates.y] != null) { Sc_Tile tile = grid[computeCoordinates.x, computeCoordinates.y].GetComponent <Sc_Tile>(); if (tile.IsSameOf(startTile)) { lastCoord = computeCoordinates; } else { outB = true; break; } } } if (outB) { outB = false; break; } } for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { Vector2Int computeCoordinates = lastCoord - (direction * i); bool inBound = computeCoordinates.x >= 0 && computeCoordinates.x < grid.GetLength(0) && computeCoordinates.y >= 0 && computeCoordinates.y < grid.GetLength(1); if (inBound && grid[computeCoordinates.x, computeCoordinates.y] != null) { Sc_Tile tile = grid[computeCoordinates.x, computeCoordinates.y].GetComponent <Sc_Tile>(); if (tile.IsSameOf(startTile)) { if (!tempValidTiles.Contains(tile)) { tempValidTiles.Add(tile); } if (!tempValidTiles.Contains(startTile)) { tempValidTiles.Add(startTile); } } else { outB = true; break; } } } if (outB) { break; } } if (tempValidTiles.Count < 3) { tempValidTiles.Clear(); } return(tempValidTiles); }