简体   繁体   English

Unity - 仅为一个场景启用VR支持

[英]Unity - enable VR support for just one scene

I'm using unity (version 2019.1.1) to build Android/IOS application, I opened a 3D project though all of the scenes in the projects are 2D except for the video player which suppose to have 2 modes VR and 360 display 我正在使用unity(版本2019.1.1)来构建Android / IOS应用程序,我打开了一个3D项目,虽然项目中的所有场景都是2D,但视频播放器除外,它假设有2种模式VR和360显示

So I need VR Support for just one scene (which is the video player, currently build with google-vr-sdk). 所以我需要VR支持只有一个场景(这是视频播放器,目前使用google-vr-sdk构建)。 The rest of the scenes are 2D and don't require VR enabling. 其余场景是2D,不需要VR启用。

However, if I choose not to enable VR settings (XR settings) the 360 video does not move via motion sensors but the rest of the application works fine. 但是,如果我选择不启用VR设置(XR设置),360视频不会通过运动传感器移动,但应用程序的其余部分工作正常。 If I do enable the VR settings I don't see the home-screen at all. 如果我启用VR设置,我根本看不到主屏幕。

My current work-around is to develop two applications, one containing just the video and the other application that has the rest of the features. 我目前的解决方案是开发两个应用程序,一个仅包含视频,另一个应用程序具有其他功能。 But I wouldn't know how to connect them. 但我不知道如何连接它们。 I want to know if there is a way to do both in one application? 我想知道是否有办法在一个应用程序中同时执行这两个操作? and If not how can I connect the 2 projects ? 如果没有,我怎么能连接2个项目?

UPDATE : I tried to export the VR Player Project as a custom unity package and then import it into my main project but then again all the 2D pages work as expected but the player does not response to movements 更新:我尝试将VR播放器项目导出为自定义统一包,然后将其导入我的主项目,但是再次将所有2D页面按预期工作但播放器不响应移动

Found this answer from a guy in reddit. 从reddit的一个人那里找到了这个答案。 it orked great for me ! 它对我来说很棒! :

Add virtuality support in the XR settings bet set None above cardboard(I'm assuming this is cardboard?). 在XR设置中添加虚拟支持下注设置无纸板(我假设这是纸板?)。

Then either use this to Start VR: 然后使用它来启动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;
   }

Or this to Stop VR: 或者这是停止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.
        }
    }
}

Make sure to call them as coroutines now I only need to take care of the splash screen 确保现在将它们称为协同程序我只需要处理启动画面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM