OVRSceneSampleController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.VR;
  4. public class OVRSceneSampleController : MonoBehaviour
  5. {
  6. private void Awake()
  7. {
  8. OVRCameraRig[] componentsInChildren = base.gameObject.GetComponentsInChildren<OVRCameraRig>();
  9. if (componentsInChildren.Length == 0)
  10. {
  11. Debug.LogWarning("OVRMainMenu: No OVRCameraRig attached.");
  12. }
  13. else if (componentsInChildren.Length > 1)
  14. {
  15. Debug.LogWarning("OVRMainMenu: More then 1 OVRCameraRig attached.");
  16. }
  17. else
  18. {
  19. this.cameraController = componentsInChildren[0];
  20. }
  21. OVRPlayerController[] componentsInChildren2 = base.gameObject.GetComponentsInChildren<OVRPlayerController>();
  22. if (componentsInChildren2.Length == 0)
  23. {
  24. Debug.LogWarning("OVRMainMenu: No OVRPlayerController attached.");
  25. }
  26. else if (componentsInChildren2.Length > 1)
  27. {
  28. Debug.LogWarning("OVRMainMenu: More then 1 OVRPlayerController attached.");
  29. }
  30. else
  31. {
  32. this.playerController = componentsInChildren2[0];
  33. }
  34. }
  35. private void Start()
  36. {
  37. if (!Application.isEditor)
  38. {
  39. Cursor.visible = false;
  40. Cursor.lockState = CursorLockMode.Locked;
  41. }
  42. if (this.cameraController != null)
  43. {
  44. this.gridCube = base.gameObject.AddComponent<OVRGridCube>();
  45. this.gridCube.SetOVRCameraController(ref this.cameraController);
  46. }
  47. }
  48. private void Update()
  49. {
  50. this.UpdateRecenterPose();
  51. this.UpdateVisionMode();
  52. if (this.playerController != null)
  53. {
  54. this.UpdateSpeedAndRotationScaleMultiplier();
  55. }
  56. if (Input.GetKeyDown(KeyCode.F11))
  57. {
  58. Screen.fullScreen = !Screen.fullScreen;
  59. }
  60. if (Input.GetKeyDown(KeyCode.M))
  61. {
  62. VRSettings.showDeviceView = !VRSettings.showDeviceView;
  63. }
  64. if (Input.GetKeyDown(this.quitKey))
  65. {
  66. Application.Quit();
  67. }
  68. }
  69. private void UpdateVisionMode()
  70. {
  71. if (Input.GetKeyDown(KeyCode.F2))
  72. {
  73. this.visionMode ^= this.visionMode;
  74. OVRManager.tracker.isEnabled = this.visionMode;
  75. }
  76. }
  77. private void UpdateSpeedAndRotationScaleMultiplier()
  78. {
  79. float num = 0f;
  80. this.playerController.GetMoveScaleMultiplier(ref num);
  81. if (Input.GetKeyDown(KeyCode.Alpha7))
  82. {
  83. num -= this.speedRotationIncrement;
  84. }
  85. else if (Input.GetKeyDown(KeyCode.Alpha8))
  86. {
  87. num += this.speedRotationIncrement;
  88. }
  89. this.playerController.SetMoveScaleMultiplier(num);
  90. float num2 = 0f;
  91. this.playerController.GetRotationScaleMultiplier(ref num2);
  92. if (Input.GetKeyDown(KeyCode.Alpha9))
  93. {
  94. num2 -= this.speedRotationIncrement;
  95. }
  96. else if (Input.GetKeyDown(KeyCode.Alpha0))
  97. {
  98. num2 += this.speedRotationIncrement;
  99. }
  100. this.playerController.SetRotationScaleMultiplier(num2);
  101. }
  102. private void UpdateRecenterPose()
  103. {
  104. if (Input.GetKeyDown(KeyCode.R))
  105. {
  106. OVRManager.display.RecenterPose();
  107. }
  108. }
  109. public KeyCode quitKey = KeyCode.Escape;
  110. public Texture fadeInTexture;
  111. public float speedRotationIncrement = 0.05f;
  112. private OVRPlayerController playerController;
  113. private OVRCameraRig cameraController;
  114. public string layerName = "Default";
  115. private bool visionMode = true;
  116. private OVRGridCube gridCube;
  117. }