VRMode.cs 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. #if UNITY_2017_2_OR_NEWER
  5. using UnityEngine.XR;
  6. #else
  7. using UnityEngine.VR;
  8. #endif
  9. namespace ZenFulcrum.EmbeddedBrowser {
  10. public class VRMode : MonoBehaviour {
  11. public bool enableVR;
  12. #if UNITY_2017_2_OR_NEWER
  13. private bool oldState;
  14. public void OnEnable() {
  15. oldState = XRSettings.enabled;
  16. XRSettings.enabled = enableVR;
  17. if (XRSettings.enabled) {
  18. //Debug.Log("VR system: " + XRSettings.loadedDeviceName + " device: " + XRDevice.model);
  19. //Unity is drunk again. This time it likes to give us y=0=floor for OpenVR and y=0=standing height
  20. //for Oculus SDK unless we call this:
  21. XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
  22. }
  23. }
  24. public void OnDisable() {
  25. XRSettings.enabled = oldState;
  26. }
  27. #else
  28. private bool oldState;
  29. public void OnEnable() {
  30. oldState = VRSettings.enabled;
  31. VRSettings.enabled = enableVR;
  32. }
  33. public void OnDisable() {
  34. VRSettings.enabled = oldState;
  35. }
  36. #endif
  37. }
  38. }