Пример #1
0
    //TODO: Refactor to factory
    void RenderPiece(TetrisPiece piece)
    {
        for (int i = 0; i < piece.size.row; i++)
        {
            for (int j = 0; j < piece.size.col; j++)
            {
                if (piece.GetPiece(i, j) == 1)
                {
                    GameObject  block       = Instantiate(tetrisBlockPrefab, this.transform);
                    BoxCollider boxCollider = block.GetComponent <BoxCollider>();

                    TetrisCell tetrisCell = block.AddComponent <TetrisCell>();
                    tetrisCell.objectSize = new Vector3(boxCollider.size.x * block.transform.localScale.x, boxCollider.size.y * block.transform.localScale.y);

                    piece.objectSize = new Vector3(boxCollider.size.x * block.transform.localScale.x, boxCollider.size.y * block.transform.localScale.y);
                    piece.SetCell(i, j, tetrisCell);
                }
            }
        }

        piece.RefreshView();
    }