Enable/Disable VR from code

后端 未结 3 1204
盖世英雄少女心
盖世英雄少女心 2020-11-27 07:29

How can I set the display to stereoscopic programmatically in Unity for an app deployed to an Android device?

I want a UI menu where the user can toggle between \"

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 08:05

     public void Awake() {
              StartCoroutine(SwitchToVR(()=>{
                    Debug.Log("Switched to VR Mode");
              }));
    
              //For disable VR Mode
              XRSettings.enabled = false;
      }
     
      IEnumerator SwitchToVR(Action callback) {
                // Device names are lowercase, as returned by `XRSettings.supportedDevices`.
                // Google original, makes you specify
                // string desiredDevice = "daydream"; // Or "cardboard".
                // XRSettings.LoadDeviceByName(desiredDevice);
                // this is slightly better;
                
                string[] Devices = new string[] { "daydream", "cardboard" };
                 XRSettings.LoadDeviceByName(Devices);
          
                // Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
                yield return null;
              
                // Now it's ok to enable VR mode.
                XRSettings.enabled = true;
                callback.Invoke();
       }
    

提交回复
热议问题