Пример #1
0
    public void SetBoardDimensions(int width, int height)
    {
        if (_isAnimating)
        {
            throw new InvalidOperationException("Cannot reset board while animating");
        }

        DestroyAllChildten();

        _boardTiles.Clear();

        GetComponent <GameBoardLayoutGroup>().CellsPerRow = width;

        for (var i = 0; i < width * height; i++)
        {
            var boardTile = Instantiate(BoardTilePrefab);
            boardTile.GameBoard = this;
            boardTile.transform.SetParent(transform);

            // we have to reset the scale due to the weird behavior of Unity Editor
            // when the new objact is instantiated
            boardTile.transform.localScale    = new Vector3(1, 1, 1);
            boardTile.transform.localPosition = new Vector3();
            boardTile.Type = _symbolDatabase.GetRandomSymbol();

            _boardTiles.Add(boardTile);
        }

        transform.localPosition = new Vector3();
    }