public static void StartRevealChain(Cell[,] level, int x, int y, Func <Cell, Vector2Int, bool> onSouldReveal) { if (!level.TryGetValue(x, y, out Cell cell)) { return; // Indexes out of range } if (cell.isRevealed || cell.hasFlag) { return; // cell is no subject revelation. } if ((level[x, y].isRevealed = onSouldReveal(cell, new Vector2Int(x, y))) == false) { return; // reveal result asks to stop chain. } if (cell.value == 0) { const int neighborCount = 8; var neighbors = ArrayPool <Vector2Int> .Get(neighborCount); LevelUtility.GetAdjacentCellsSquare(new Vector2Int(x, y), neighbors); for (int i = 0; i < neighborCount; i++) { Vector2Int nPos = neighbors[i]; StartRevealChain(level, nPos.x, nPos.y, onSouldReveal); } ArrayPool <Vector2Int> .Release(neighbors); } }