Unity - enable VR support for just one scene

1.6k views Asked by At

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

So I need VR Support for just one scene (which is the video player, currently build with google-vr-sdk). The rest of the scenes are 2D and don't require VR enabling.

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. If I do enable the VR settings I don't see the home-screen at all.

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 ?

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

1

There are 1 answers

0
HadarDayan On

Found this answer from a guy in reddit. it orked great for me ! :

Add virtuality support in the XR settings bet set None above cardboard(I'm assuming this is cardboard?).

Then either use this to Start 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:

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