GoogleVR切换至Cardboard改变了视角

时间:2019-07-04 15:00:20

标签: unity3d google-vr gvr-android-sdk

我正在制作一个应用程序,您可以在其中使用按钮在VR和Magic Window之间切换。 我曾经使用旧的Google Cardboard SDK,但效果很好,但现在我改用GoogleVR 1.2,这让我头疼:
切换到VR模式后,整个世界在Z轴上倾斜约45度(在水平方向上,前方和后方分别倾斜45度和45度。)

我正在使用GyroController.cs(以下代码段)在“魔术窗口”模式下移动相机。当我切换到Cardboard时,transform.localRotation会重置,但这似乎无济于事。

VR模式控制器: VRController.cs:

    private void LoadCardboard()
    {
        GyroController GC = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GyroController>();
        if (GC != null){
            GC.resetValues();   // check GyroController.cs below for this function
        } else {
            // logging error here
        }

        StartCoroutine(LoadDevice("cardboard"));

    }

    IEnumerator LoadDevice(string newDevice)
    {
            XRSettings.LoadDeviceByName(newDevice);
            yield return null;
            XRSettings.enabled = true;//(newDevice == "cardboard");

            // if (newDevice == "cardboard"){
            //     GameObject.Find("LevelLoader").GetComponent<LevelLoader>().LoadLevel("Demo_Scene");
            // } // here I tried reloading the scene but that didn't help.
    }

Magic Window控制器: GyroController.cs:

void Update () {
    #if UNITY_EDITOR
      return;
    #endif

    if (XRSettings.enabled) {
      return;
    }

    CheckDrag();

    transform.localRotation =
      Quaternion.Euler (0f, -dragYawDegrees, 0f) *
      Quaternion.Euler (90f, 0f, 0f) *
      Input.gyro.attitude *
      Quaternion.Euler (0f, 0f, 180f);
  }
public void resetValues() {
    transform.localRotation = Quaternion.Euler(0.0f, -dragYawDegrees, 0.0f);
    dragYawDegrees = PlayerPrefs.GetFloat("dragYawDegrees", 0.0f);  // this is for the next time when switching back to magic window mode to keep same yaw
  }

切换到Cardboard设备I后: EXPECT:地平线在玩家的视线范围内。 GOT:地平线在Z轴上移动(前地平线高45度,后地平线-低45度)

0 个答案:

没有答案