从reddit的一个人那里找到了这个答案。它对我来说很棒!:
在纸板上方的 XR 设置赌注中添加虚拟支持(我假设这是纸板?)。
然后使用它来启动 VR:
IEnumerator EnableCardboard() {
// Empty string loads the "None" device.
XRSettings.LoadDeviceByName("CardBoard");
// Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
yield return null;
// Not needed, since loading the None (`""`) device takes care of
this.XRSettings.enabled = true;
}
或者停止 VR:
public IEnumerator StopCardboard(){
XRSettings.LoadDeviceByName("");
yield return null;
XRSettings.enabled = false;
ResetCameras();
Screen.orientation = ScreenOrientation.Portrait;
}
void ResetCameras() {
// Camera looping logic copied from GvrEditorEmulator.cs
for (int i = 0; i < Camera.allCameras.Length; i++) {
Camera cam = Camera.allCameras[i];
if (cam.enabled && cam.stereoTargetEye != StereoTargetEyeMask.None) {
// Reset local position.
// Only required if you change the camera's local position while in 2D mode.
cam.transform.localPosition = Vector3.zero;
// Reset local rotation.
// Only required if you change the camera's local rotation while in 2D mode.
cam.transform.localRotation = Quaternion.identity;
// No longer needed, see issue github.com/googlevr/gvr-unity-sdk/issues/628.
// cam.ResetAspect();
// No need to reset `fieldOfView`, since it's reset automatically.
}
}
}
确保现在将它们称为协程我只需要处理启动画面