public GameField BuildGameField(int fieldSizeX, int fieldSizeY, GameObject fieldCellPrefab) { GameField gameField = new GameField(); GameFieldCell[,] gameFieldCells = new GameFieldCell[fieldSizeX, fieldSizeY]; GameObject gameFieldParent = new GameObject(); gameFieldParent.name = "GameFieldParent"; for (int i = 0; i < fieldSizeX; i++) { for (int j = 0; j < fieldSizeY; j++) { GameFieldCell gameFieldCell = new GameFieldCell(i, j); GameObject go = GameObject.Instantiate(fieldCellPrefab); go.transform.SetParent(gameFieldParent.transform); GameFieldCellComponent gameFieldCellComponent = go.GetComponent <GameFieldCellComponent>(); gameFieldCellComponent.InitConnection(gameFieldCell); gameFieldCellComponent.MoveToCurrentPosition(); gameFieldCells[i, j] = gameFieldCell; } } gameField.gameFieldCells = gameFieldCells; return(gameField); }
GameFieldCell[,] InstanciateGameFieldWithCells() { var cellWidth = _gameFieldRect.rect.width / _rows; var cellHeight = _gameFieldRect.rect.height / _columns; var result = new GameFieldCell[_rows, _columns]; for (int i = 0; i < _rows; i++) { for (int j = 0; j < _columns; j++) { var cell = (GameFieldCell)GameObject.Instantiate(_gameFieldCellPrefab, _gameFieldRect); var rt = cell.GetComponent <RectTransform>(); rt.anchorMin = new Vector2( ((float)i + 0.5f) / (float)_rows, ((float)j + 0.5f) / (float)_columns ); rt.anchorMax = rt.anchorMin; rt.sizeDelta = new Vector2(cellWidth, cellHeight); result[i, j] = cell; } } return(result); }
public void InitConnection(GameFieldCell gameFieldCell) { this.gameFieldCell = gameFieldCell; gameFieldCell.gameFieldCellComponent = this; }