| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using Cinemachine; |
| | 5 | | using Cinemachine.Utility; |
| | 6 | | using DCL.Camera; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | public class SmoothAxisProvider : MonoBehaviour, AxisState.IInputAxisProvider |
| | 11 | | { |
| | 12 | | public Vector3 dampTime; |
| | 13 | |
|
| | 14 | | private Vector3 axis = new Vector3(); |
| | 15 | | private Vector3 axisTarget = new Vector3(); |
| | 16 | |
|
| | 17 | | public InputAction_Measurable axisX; |
| | 18 | | public InputAction_Measurable axisY; |
| | 19 | | private InputSpikeFixer[] inputSpikeFixer; |
| | 20 | |
|
| | 21 | | private void Awake() |
| | 22 | | { |
| 98 | 23 | | inputSpikeFixer = new [] |
| | 24 | | { |
| 2199 | 25 | | new InputSpikeFixer(() => Utils.IsCursorLocked ? CursorLockMode.Locked : CursorLockMode.None), |
| 2297 | 26 | | new InputSpikeFixer(() => Utils.IsCursorLocked ? CursorLockMode.Locked : CursorLockMode.None) |
| | 27 | | }; |
| 98 | 28 | | } |
| | 29 | | void Update() |
| | 30 | | { |
| 2198 | 31 | | axisTarget[0] = axisX.GetValue(); |
| 2198 | 32 | | axisTarget[1] = axisY.GetValue(); |
| 2198 | 33 | | axis += Damper.Damp(axisTarget - axis, dampTime, Time.deltaTime); |
| 2198 | 34 | | } |
| | 35 | |
|
| | 36 | | public float GetAxisValue(int axis) |
| | 37 | | { |
| 4300 | 38 | | return inputSpikeFixer[axis].GetValue(this.axis[axis]); |
| | 39 | | } |
| | 40 | | } |