6 using UnityEngine.EventSystems;
10 public float rotationSpeedMouse = 2.0f;
11 public float rotationSpeedVive = 200.0f;
13 private Quaternion targetRotation;
14 public float autoRotateSpeed = 720f;
15 private float rotationStartTime = 0;
16 private float rotationTime = 0.3f;
18 private Vector3 previousVivePos;
19 private bool rotating =
false;
23 targetRotation = transform.localRotation;
28 if (UI.Core.instance.layoutSystem.activeScreen == UI.Screen.center) {
30 InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice;
31 if (inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.Mouse) {
33 if (Input.GetMouseButton (1) || Input.GetKey (KeyCode.M)) {
34 float inputH = -Input.GetAxis (
"Mouse X");
35 float inputV = -Input.GetAxis (
"Mouse Y");
37 Vector3 upVector = Camera.main.transform.up;
38 Vector3 rightVector = Camera.main.transform.right;
39 transform.RotateAround (transform.position, upVector, inputH * rotationSpeedMouse);
40 transform.RotateAround (transform.position, rightVector, -inputV * rotationSpeedMouse);
42 targetRotation = transform.localRotation;
44 }
else if( inputDevice.getDeviceType() == InputDeviceManager.InputDeviceType.ViveController ) {
48 UnityEngine.EventSystems.PointerEventData.FramePressState triggerState = lc.triggerButtonState;
49 if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed) {
51 previousVivePos = lc.transform.localPosition;
52 }
else if (triggerState == UnityEngine.EventSystems.PointerEventData.FramePressState.Released) {
54 previousVivePos =
new Vector3 (0, 0, 0);
57 Vector3 upVector = Camera.main.transform.up;
58 Vector3 rightVector = Camera.main.transform.right;
59 transform.RotateAround (transform.position, upVector, (previousVivePos.x - lc.transform.localPosition.x) * rotationSpeedVive);
60 transform.RotateAround (transform.position, rightVector, -(previousVivePos.y - lc.transform.localPosition.y) * rotationSpeedVive);
61 targetRotation = transform.localRotation;
62 previousVivePos = lc.transform.localPosition;
70 transform.localRotation = Quaternion.Slerp( transform.localRotation, targetRotation, (Time.time - rotationStartTime)/rotationTime );
74 public void setTargetOrientation( Quaternion orientation,
float timeForRotation = 0f )
76 targetRotation = orientation;
77 rotationStartTime = Time.time;
78 if (timeForRotation == 0f) {
79 transform.localRotation = orientation;
82 rotationTime = timeForRotation;