123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using UnityEngine;
- using UnityEngine.VR;
- namespace RenderHeads.Media.AVProVideo.Demos
- {
- public class SphereDemo : MonoBehaviour
- {
- private void Start()
- {
- if (VRDevice.isPresent)
- {
- return;
- }
- if (SystemInfo.supportsGyroscope)
- {
- Input.gyro.enabled = true;
- base.transform.parent.Rotate(new Vector3(90f, 0f, 0f));
- }
- }
- private void OnDestroy()
- {
- if (SystemInfo.supportsGyroscope)
- {
- Input.gyro.enabled = false;
- }
- }
- private void Update()
- {
- if (VRDevice.isPresent)
- {
- if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
- {
- InputTracking.Recenter();
- }
- if (Input.GetKeyDown(KeyCode.V))
- {
- VRSettings.enabled = !VRSettings.enabled;
- }
- }
- else
- {
- if (SystemInfo.supportsGyroscope)
- {
- base.transform.localRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
- }
- else if (Input.GetMouseButton(0))
- {
- float num = 40f * -Input.GetAxis("Mouse X") * Time.deltaTime;
- float num2 = 40f * Input.GetAxis("Mouse Y") * Time.deltaTime;
- num = Mathf.Clamp(num, -0.5f, 0.5f);
- num2 = Mathf.Clamp(num2, -0.5f, 0.5f);
- this._spinX += num;
- this._spinY += num2;
- }
- if (!Mathf.Approximately(this._spinX, 0f) || !Mathf.Approximately(this._spinY, 0f))
- {
- base.transform.Rotate(Vector3.up, this._spinX);
- base.transform.Rotate(Vector3.right, this._spinY);
- this._spinX = Mathf.MoveTowards(this._spinX, 0f, 5f * Time.deltaTime);
- this._spinY = Mathf.MoveTowards(this._spinY, 0f, 5f * Time.deltaTime);
- }
- }
- }
- private float _spinX;
- private float _spinY;
- }
- }
|