示例#1
0
    private void ManageGameFieldObject(GameObject piece, int playerId, Quaternion randomInstanciationRotation, List <Material> randomPieceColor)
    {
        PieceMetadatas pieceMetadatas = PieceUtils.FetchPieceMetadataScript(piece);

        float positionCorrection = 0f;

        if (pieceMetadatas.IsExcentered)
        {
            positionCorrection = 0.5f;
        }

        GameObject field = this.PlayersField[playerId];

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(field.transform.transform.GetChild(0).gameObject);

        Vector3 instantiatePosition = new Vector3(
            fieldsize.x / 2 + field.transform.position.x - 0.5f + positionCorrection
            , 0.5f
            , fieldsize.z + field.transform.position.z - 1.5f);

        GameObject instanciatedPiece = Instantiate(piece, instantiatePosition, randomInstanciationRotation);


        PieceController genericController = null;

        if (ApplicationUtils.IsTypeComputer(playerId))
        {
            genericController = PieceUtils.FetchPieceComputerPieceControllerScript(instanciatedPiece);
        }
        else
        {
            genericController = PieceUtils.FetchPiecePlayerPieceControllerScript(instanciatedPiece);
        }

        genericController.enabled = true;
        genericController.OwnerId = playerId;
        genericController.Field   = field;

        for (int i = 0; i < randomPieceColor.Count; i++)
        {
            instanciatedPiece.transform.GetChild(i).GetComponent <MeshRenderer>().material = randomPieceColor[i];
        }

        PieceMetadatas instanciatedPieceMetadataScript = PieceUtils.FetchPieceMetadataScript(instanciatedPiece);

        instanciatedPieceMetadataScript.IsPieceReady = true;

        //Update parent piece name and the children too thank to the pieceId
        this.UpdatePiecesName(instanciatedPiece);
        this.UpdatePieceChildrenTagName(playerId, instanciatedPiece);
        this.playersCurrentGamePiece[playerId] = instanciatedPiece;
    }