public static int[] TryCollectFullRows(this IGridManager gridManager) { var grid = gridManager.Grid; var dimensions = grid.Dimensions; var fullRows = gridManager.GetFullRows().ToArray(); foreach (var row in fullRows) { for (var x = 0; x < dimensions.x; x++) { Object.Destroy(gridManager.GetBlock(new Vector2Int(x, row))); for (var y = row; y >= 1; y--) { var currentRowCoordinate = new Vector2Int(x, y); var previousRowCoordinate = new Vector2Int(x, y - 1); var currentBlock = gridManager.GetBlock(previousRowCoordinate); gridManager.SetBlock(currentRowCoordinate, currentBlock); if (currentBlock != null) { currentBlock.transform.position = grid.GetWorldCoordinate(currentRowCoordinate); } gridManager.SetBlock(previousRowCoordinate, null); } } } return(fullRows); }
public static void RegisterShape( this IGridManager gridManager, Vector2Int coordinate, Shape currentShape, GameObject[,] blocks) { var size = currentShape.Size; var sizeX = size.x; var sizeY = size.y; for (var y = 0; y < sizeY; y++) { for (var x = 0; x < sizeX; x++) { var currentBlock = blocks[x, y]; gridManager.SetBlock( new Vector2Int( coordinate.x + x + currentShape.Offset.x, coordinate.y + y + currentShape.Offset.y), currentBlock); if (currentBlock != null) { currentBlock.transform.parent = null; } } } }