Files
FueraDeEscala/Assets/Game Kit Controller/Scripts/Input/InputAxisWrapper.cs

112 lines
2.3 KiB
C#
Raw Normal View History

2026-03-29 23:03:14 -07:00
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
public static class InputAxisWrapper
{
#if ENABLE_INPUT_SYSTEM
private static InputAction moveAction;
private static InputAction lookAction;
#endif
private static Vector2 smoothedMove = Vector2.zero;
#if ENABLE_INPUT_SYSTEM
public static void InitializeMove (InputAction move)
{
if (move == null) {
Debug.LogError ("InputAxisWrapper: move action not found");
return;
}
moveAction = move;
moveAction.Enable ();
}
public static void InitializeLook (InputAction look)
{
if (look == null) {
Debug.LogError ("InputAxisWrapper: look action not found");
return;
}
lookAction = look;
lookAction.Enable ();
}
#endif
public static float GetAxisHorizontal ()
{
#if ENABLE_INPUT_SYSTEM
if (moveAction == null) return 0f;
return moveAction.ReadValue<Vector2> ().x;
#else
return 0;
#endif
}
public static float GetAxisVertical ()
{
#if ENABLE_INPUT_SYSTEM
if (moveAction == null) return 0f;
return moveAction.ReadValue<Vector2> ().y;
#else
return 0;
#endif
}
public static Vector2 GetMoveAxis (float smoothSpeed)
{
Vector2 currentValue = Vector2.zero;
#if ENABLE_INPUT_SYSTEM
currentValue = moveAction.ReadValue<Vector2> ();
#endif
smoothedMove = Vector2.Lerp (smoothedMove, currentValue, smoothSpeed * Time.deltaTime);
if (currentValue.x == 0) {
if (Mathf.Abs (smoothedMove.x) < 0.001f) {
smoothedMove.x = 0;
}
}
if (currentValue.y == 0) {
if (Mathf.Abs (smoothedMove.y) < 0.001f) {
smoothedMove.y = 0;
}
}
return smoothedMove;
}
public static void resetSmoothedGetMoveAxis ()
{
smoothedMove = Vector2.zero;
}
public static Vector2 GetMoveRawAxis ()
{
#if ENABLE_INPUT_SYSTEM
return moveAction.ReadValue<Vector2> ();
#else
return Vector2.zero;
#endif
}
public static Vector2 GetLookAxis ()
{
#if ENABLE_INPUT_SYSTEM
return lookAction.ReadValue<Vector2> ();
#else
return Vector2.zero;
#endif
}
}