123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using UnityEngine;
- #if UNITY_2017_2_OR_NEWER
- using UnityEngine.XR;
- #else
- using XRSettings = UnityEngine.VR.VRSettings;
- #endif
- namespace Vuplex.Demos {
-
-
-
-
-
- class CameraRotator : MonoBehaviour {
- public GameObject InstructionMessage;
- private bool _legacyInputManagerDisabled;
- Vector2 _rotationFromMouse;
-
- #if !UNITY_WEBGL
- void Start() {
-
- if (!XRSettings.enabled) {
- Input.gyro.enabled = true;
- }
- #if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
- _legacyInputManagerDisabled = true;
- #endif
-
- if (Application.isEditor && InstructionMessage != null && !_legacyInputManagerDisabled) {
- InstructionMessage.SetActive(true);
- } else {
- InstructionMessage = null;
- }
- }
-
-
-
-
-
- void Update() {
-
- if (InstructionMessage != null && !_legacyInputManagerDisabled && Input.GetMouseButtonDown(0)) {
- InstructionMessage.SetActive(false);
- InstructionMessage = null;
- }
- if (XRSettings.enabled) {
-
- return;
- }
- if (SystemInfo.supportsGyroscope) {
- Camera.main.transform.Rotate(
- -Input.gyro.rotationRateUnbiased.x,
- -Input.gyro.rotationRateUnbiased.y,
- Input.gyro.rotationRateUnbiased.z
- );
- } else if (!_legacyInputManagerDisabled && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) {
- float sensitivity = 10f;
- float maxYAngle = 80f;
- _rotationFromMouse.x += Input.GetAxis("Mouse X") * sensitivity;
- _rotationFromMouse.y -= Input.GetAxis("Mouse Y") * sensitivity;
- _rotationFromMouse.x = Mathf.Repeat(_rotationFromMouse.x, 360);
- _rotationFromMouse.y = Mathf.Clamp(_rotationFromMouse.y, -maxYAngle, maxYAngle);
- Camera.main.transform.rotation = Quaternion.Euler(_rotationFromMouse.y, _rotationFromMouse.x, 0);
- }
- }
- #endif
- }
- }
|