void Awake() {
// calculate the cell size
RectTransform rectTransform = transform as RectTransform;
Vector2 boardSize = rectTransform.sizeDelta;
GridLayoutGroup gridLayout = GetComponent<GridLayoutGroup>();
cellSize = new Vector2(boardSize.x / BOARD_GRID_SIZE, boardSize.y / BOARD_GRID_SIZE);
gridLayout.cellSize = cellSize;
// instantiate all the squares for the grid
for (int y = 0; y < BOARD_GRID_SIZE; y++) {
for (int x = 0; x < BOARD_GRID_SIZE; x++) {
GameObject squarePrefab = (x + y) % 2 == 0 ? whiteSquarePrefab : blackSquarePrefab;
IntVector2 boardPosition = new IntVector2(x, y);
InstantiateSquare(squarePrefab, boardPosition);
}
}
}