SphereDemo.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.VR;
  4. namespace RenderHeads.Media.AVProVideo.Demos
  5. {
  6. public class SphereDemo : MonoBehaviour
  7. {
  8. private void Start()
  9. {
  10. if (VRDevice.isPresent)
  11. {
  12. return;
  13. }
  14. if (SystemInfo.supportsGyroscope)
  15. {
  16. Input.gyro.enabled = true;
  17. base.transform.parent.Rotate(new Vector3(90f, 0f, 0f));
  18. }
  19. }
  20. private void OnDestroy()
  21. {
  22. if (SystemInfo.supportsGyroscope)
  23. {
  24. Input.gyro.enabled = false;
  25. }
  26. }
  27. private void Update()
  28. {
  29. if (VRDevice.isPresent)
  30. {
  31. if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
  32. {
  33. InputTracking.Recenter();
  34. }
  35. if (Input.GetKeyDown(KeyCode.V))
  36. {
  37. VRSettings.enabled = !VRSettings.enabled;
  38. }
  39. }
  40. else
  41. {
  42. if (SystemInfo.supportsGyroscope)
  43. {
  44. base.transform.localRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
  45. }
  46. else if (Input.GetMouseButton(0))
  47. {
  48. float num = 40f * -Input.GetAxis("Mouse X") * Time.deltaTime;
  49. float num2 = 40f * Input.GetAxis("Mouse Y") * Time.deltaTime;
  50. num = Mathf.Clamp(num, -0.5f, 0.5f);
  51. num2 = Mathf.Clamp(num2, -0.5f, 0.5f);
  52. this._spinX += num;
  53. this._spinY += num2;
  54. }
  55. if (!Mathf.Approximately(this._spinX, 0f) || !Mathf.Approximately(this._spinY, 0f))
  56. {
  57. base.transform.Rotate(Vector3.up, this._spinX);
  58. base.transform.Rotate(Vector3.right, this._spinY);
  59. this._spinX = Mathf.MoveTowards(this._spinX, 0f, 5f * Time.deltaTime);
  60. this._spinY = Mathf.MoveTowards(this._spinY, 0f, 5f * Time.deltaTime);
  61. }
  62. }
  63. }
  64. private float _spinX;
  65. private float _spinY;
  66. }
  67. }