| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using Cinemachine; |
| | 5 | | using DCL; |
| | 6 | | using DCL.Camera; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | public class OverrideCinemachineAxisInput : MonoBehaviour |
| | 10 | | { |
| | 11 | | public const string MOUSE_Y_AXIS = "Mouse Y"; |
| | 12 | |
|
| | 13 | | [Serializable] |
| | 14 | | public struct AxisToMeasurableAction |
| | 15 | | { |
| | 16 | | public string axisName; |
| | 17 | | public InputAction_Measurable measurableAction; |
| | 18 | | } |
| | 19 | |
|
| | 20 | | [SerializeField] private AxisToMeasurableAction[] axisToMeasurableActions; |
| | 21 | | private Dictionary<string, InputAction_Measurable> cachedAxisToMeasurableActions; |
| | 22 | | private InputSpikeFixer inputSpikeFixer; |
| | 23 | | private bool invertMouseY = false; |
| | 24 | |
|
| | 25 | | private void Awake() |
| | 26 | | { |
| 2985 | 27 | | cachedAxisToMeasurableActions = axisToMeasurableActions.ToDictionary(x => x.axisName, x => x.measurableAction); |
| 597 | 28 | | CinemachineCore.GetInputAxis = OverrideGetAxis; |
| 7910 | 29 | | inputSpikeFixer = new InputSpikeFixer(() => Cursor.lockState); |
| 597 | 30 | | DataStore.i.camera.invertYAxis.OnChange += SetInvertYAxis; |
| 597 | 31 | | invertMouseY = DataStore.i.camera.invertYAxis.Get(); |
| 597 | 32 | | } |
| | 33 | |
|
| | 34 | | private float OverrideGetAxis(string axisName) |
| | 35 | | { |
| 6716 | 36 | | if (!cachedAxisToMeasurableActions.ContainsKey(axisName)) |
| 0 | 37 | | return 0; |
| | 38 | |
|
| 6716 | 39 | | float value = cachedAxisToMeasurableActions[axisName].GetValue(); |
| 6716 | 40 | | if (axisName.Equals(MOUSE_Y_AXIS) && invertMouseY) |
| | 41 | | { |
| 0 | 42 | | value = -value; |
| | 43 | | } |
| 6716 | 44 | | return inputSpikeFixer.GetValue(value); |
| | 45 | | } |
| | 46 | |
|
| | 47 | | private void SetInvertYAxis(bool current, bool previous) |
| | 48 | | { |
| 13 | 49 | | invertMouseY = current; |
| 13 | 50 | | } |
| | 51 | |
|
| | 52 | | private void OnDestroy() |
| | 53 | | { |
| 597 | 54 | | DataStore.i.camera.invertYAxis.OnChange -= SetInvertYAxis; |
| 597 | 55 | | } |
| | 56 | |
|
| | 57 | |
|
| | 58 | | } |