Created
March 22, 2021 09:44
-
-
Save unitycoder/3a2e1080134fb7cc6ac48dc31afbe9d9 to your computer and use it in GitHub Desktop.
toggle between 2d and Google Cardboard (2020 Unity XR)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://forum.unity.com/threads/toggle-between-2d-and-google-cardboard.902378/#post-6959573 | |
Coroutine StartVR() | |
{ | |
return StartCoroutine(startVRRoutine()); | |
IEnumerator startVRRoutine() | |
{ | |
// Add error handlers for both Instance and Manager | |
var xrManager = XRGeneralSettings.Instance.Manager; | |
if (!xrManager.isInitializationComplete) | |
yield return xrManager.InitializeLoader(); | |
if (xrManager.activeLoader != null) | |
xrManager.StartSubsystems(); | |
// Add else with error handling | |
} | |
} | |
void StopXR() | |
{ | |
var xrManager = XRGeneralSettings.Instance.Manager; | |
if (!xrManager.isInitializationComplete) | |
return; // Safety check | |
xrManager.StopSubsystems(); | |
xrManager.DeinitializeLoader(); | |
} | |
// And perhaps this too, if you are experiencig a distorted or stretched screen after exiting VR: | |
camera.ResetAspect(); | |
camera.fieldOfView = defaultFov; | |
camera.ResetProjectionMatrix(); | |
camera.ResetWorldToCameraMatrix(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tips googlevr/cardboard#140