1 using System
.Collections
.Generic
;
4 namespace UnityEngine
.Experimental
.Rendering
7 public class FreeCamera
: MonoBehaviour
9 public float m_LookSpeedController
= 120f
;
10 public float m_LookSpeedMouse
= 10.0f
;
11 public float m_MoveSpeed
= 10.0f
;
12 public float m_MoveSpeedIncrement
= 2.5f
;
13 public float m_Turbo
= 10.0f
;
15 private static string kMouseX
= "Mouse X";
16 private static string kMouseY
= "Mouse Y";
17 private static string kRightStickX
= "Controller Right Stick X";
18 private static string kRightStickY
= "Controller Right Stick Y";
19 private static string kVertical
= "Vertical";
20 private static string kHorizontal
= "Horizontal";
22 private static string kYAxis
= "YAxis";
23 private static string kSpeedAxis
= "Speed Axis";
33 List
<InputManagerEntry
> inputEntries
= new List
<InputManagerEntry
>();
36 inputEntries
.Add(new InputManagerEntry { name = kRightStickX, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fourth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f }
);
37 inputEntries
.Add(new InputManagerEntry { name = kRightStickY, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fifth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f, invert = true }
);
39 inputEntries
.Add(new InputManagerEntry { name = kYAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page up", altBtnPositive = "joystick button 5", btnNegative = "page down", altBtnNegative = "joystick button 4", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }
);
41 inputEntries
.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "home", btnNegative = "end", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }
);
42 inputEntries
.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }
);
44 InputRegistering
.RegisterInputs(inputEntries
);
50 // If the debug menu is running, we don't want to conflict with its inputs.
51 if (DebugManager
.instance
.displayRuntimeUI
)
54 float inputRotateAxisX
= 0.0f
;
55 float inputRotateAxisY
= 0.0f
;
56 if (Input
.GetMouseButton(1))
58 inputRotateAxisX
= Input
.GetAxis(kMouseX
) * m_LookSpeedMouse
;
59 inputRotateAxisY
= Input
.GetAxis(kMouseY
) * m_LookSpeedMouse
;
61 inputRotateAxisX
+= (Input
.GetAxis(kRightStickX
) * m_LookSpeedController
* Time
.deltaTime
);
62 inputRotateAxisY
+= (Input
.GetAxis(kRightStickY
) * m_LookSpeedController
* Time
.deltaTime
);
64 float inputChangeSpeed
= Input
.GetAxis(kSpeedAxis
);
65 if (inputChangeSpeed
!= 0.0f
)
67 m_MoveSpeed
+= inputChangeSpeed
* m_MoveSpeedIncrement
;
68 if (m_MoveSpeed
< m_MoveSpeedIncrement
) m_MoveSpeed
= m_MoveSpeedIncrement
;
71 float inputVertical
= Input
.GetAxis(kVertical
);
72 float inputHorizontal
= Input
.GetAxis(kHorizontal
);
73 float inputYAxis
= Input
.GetAxis(kYAxis
);
75 bool moved
= inputRotateAxisX
!= 0.0f
|| inputRotateAxisY
!= 0.0f
|| inputVertical
!= 0.0f
|| inputHorizontal
!= 0.0f
|| inputYAxis
!= 0.0f
;
78 float rotationX
= transform
.localEulerAngles
.x
;
79 float newRotationY
= transform
.localEulerAngles
.y
+ inputRotateAxisX
;
81 // Weird clamping code due to weird Euler angle mapping...
82 float newRotationX
= (rotationX
- inputRotateAxisY
);
83 if (rotationX
<= 90.0f
&& newRotationX
>= 0.0f
)
84 newRotationX
= Mathf
.Clamp(newRotationX
, 0.0f
, 90.0f
);
85 if (rotationX
>= 270.0f
)
86 newRotationX
= Mathf
.Clamp(newRotationX
, 270.0f
, 360.0f
);
88 transform
.localRotation
= Quaternion
.Euler(newRotationX
, newRotationY
, transform
.localEulerAngles
.z
);
90 float moveSpeed
= Time
.deltaTime
* m_MoveSpeed
;
91 if (Input
.GetMouseButton(1))
92 moveSpeed
*= Input
.GetKey(KeyCode
.LeftShift
) ? m_Turbo
: 1.0f
;
94 moveSpeed
*= Input
.GetAxis("Fire1") > 0.0f
? m_Turbo
: 1.0f
;
95 transform
.position
+= transform
.forward
* moveSpeed
* inputVertical
;
96 transform
.position
+= transform
.right
* moveSpeed
* inputHorizontal
;
97 transform
.position
+= Vector3
.up
* moveSpeed
* inputYAxis
;