Ejemplo n.º 1
0
    void CreatePieces()
    {
        // Instantiate all pieces according to board data
        teamPiecesArray[0] = new TeamPieces();
        teamPiecesArray[1] = new TeamPieces();

        Dictionary <EPieceType, GameObject> crtTeamPrefabs = null;
        int crtPos = 0;

        foreach (BoardSquare square in boardState.Squares)
        {
            crtTeamPrefabs = (square.Team == EChessTeam.White) ? WhitePiecesPrefab : BlackPiecesPrefab;
            if (square.Piece != EPieceType.None)
            {
                GameObject crtPiece = Instantiate <GameObject>(crtTeamPrefabs[square.Piece]);
                teamPiecesArray[(int)square.Team].StorePiece(crtPiece, square.Piece);

                // set position
                Vector3 piecePos = boardTransform.position;
                piecePos.y += zOffset;
                piecePos.x  = -widthOffset + crtPos % BOARD_SIZE;
                piecePos.z  = -widthOffset + crtPos / BOARD_SIZE;
                crtPiece.transform.position = piecePos;
            }
            crtPos++;
        }
    }
Ejemplo n.º 2
0
    void CreatePieces()
    {
        // Instantiate all pieces according to board data
        if (teamPiecesArray[0] == null)
        {
            teamPiecesArray[0] = new TeamPieces();
        }
        if (teamPiecesArray[1] == null)
        {
            teamPiecesArray[1] = new TeamPieces();
        }

        Dictionary <EPieceType, GameObject> crtTeamPrefabs = null;

        foreach (PieceData data in boardState.bitBoard.GetAllPiecesList())
        {
            crtTeamPrefabs = (data.team == EChessTeam.White) ? WhitePiecesPrefab : BlackPiecesPrefab;
            if (data.piece != EPieceType.None)
            {
                GameObject crtPiece = Instantiate <GameObject>(crtTeamPrefabs[data.piece]);
                teamPiecesArray[(int)data.team].StorePiece(crtPiece, data.piece);

                // set position
                Vector3 piecePos = boardTransform.position;
                piecePos.y += zOffset;
                piecePos.x  = -widthOffset + data.pos % BOARD_SIZE;
                piecePos.z  = -widthOffset + data.pos / BOARD_SIZE;
                crtPiece.transform.position = piecePos;
            }
        }
    }