Search Unity

Disable VR on request

Discussion in 'VR' started by lcaExtende, Sep 10, 2019.

  1. lcaExtende

    lcaExtende

    Joined:
    Sep 2, 2019
    Posts:
    25
    Hi everyone !

    Is it possible to disable VR (and VR headset) by code to display forms on the computer screen and launch VR after pressing a UI button?

    Display at startup a configuration screen of the scene (with 2D UI) and launch the VR following the click of a button "RUN VR".

    I use Acer WMR Headset.
    It's Universal Windows project

    Starting scene :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.UI;
    6. using UnityEngine.XR;
    7.  
    8. public class MainForm : MonoBehaviour
    9. {
    10.     [SerializeField]
    11.     private Button _startRvBtn;
    12.  
    13.     void Awake()
    14.     {
    15.         StartCoroutine(StopVRRoutine());
    16.         _startRvBtn.onClick.AddListener(LoadRVScene);
    17.     }
    18.  
    19.     IEnumerator StopVRRoutine()
    20.     {
    21.         XRSettings.LoadDeviceByName("");
    22.         yield return null;
    23.         XRSettings.enabled = false;
    24.     }
    25.  
    26.     void LoadRVScene()
    27.     {
    28.         SceneManager.LoadScene("VRScene");
    29.     }
    30.  
    31.  
    32. }
    33.  

    And VR Scene :

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.XR;
    4.  
    5. public class StartVR : MonoBehaviour
    6. {
    7.     void Awake()
    8.     {
    9.         StartCoroutine(StartVRRoutine());
    10.     }
    11.  
    12.     IEnumerator StartVRRoutine()
    13.     {
    14.         XRSettings.LoadDeviceByName(new string[] { "OpenVR", "Oculus", "None" });
    15.         yield return null;
    16.         XRSettings.enabled = true;
    17.     }
    18. }
    19.  
    Thank you for your help :(
     
  2. Corysia

    Corysia

    Joined:
    Mar 14, 2018
    Posts:
    108
    I just responded in another thread about this topic. I had decided not to support switching while the app was running, tho I don't see why it wouldn't be possible. You can do this in WebVR with BabylonJS, for example. I haven't seen, or at least not noticed, many games that support this. I have a few that support VR and non-VR, but that choice is made on startup.

    You'd need to switch your camera, player controller, canvas and UI, and input system. I'm interested in hearing about your progress on this.