[英]Unity - enable VR support for just one scene
我正在使用unity(版本2019.1.1)来构建Android / IOS应用程序,我打开了一个3D项目,虽然项目中的所有场景都是2D,但视频播放器除外,它假设有2种模式VR和360显示
所以我需要VR支持只有一个场景(这是视频播放器,目前使用google-vr-sdk构建)。 其余场景是2D,不需要VR启用。
但是,如果我选择不启用VR设置(XR设置),360视频不会通过运动传感器移动,但应用程序的其余部分工作正常。 如果我启用VR设置,我根本看不到主屏幕。
我目前的解决方案是开发两个应用程序,一个仅包含视频,另一个应用程序具有其他功能。 但我不知道如何连接它们。 我想知道是否有办法在一个应用程序中同时执行这两个操作? 如果没有,我怎么能连接2个项目?
更新:我尝试将VR播放器项目导出为自定义统一包,然后将其导入我的主项目,但是再次将所有2D页面按预期工作但播放器不响应移动
从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.
}
}
}
确保现在将它们称为协同程序我只需要处理启动画面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.