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 ().x; #else return 0; #endif } public static float GetAxisVertical () { #if ENABLE_INPUT_SYSTEM if (moveAction == null) return 0f; return moveAction.ReadValue ().y; #else return 0; #endif } public static Vector2 GetMoveAxis (float smoothSpeed) { Vector2 currentValue = Vector2.zero; #if ENABLE_INPUT_SYSTEM currentValue = moveAction.ReadValue (); #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 (); #else return Vector2.zero; #endif } public static Vector2 GetLookAxis () { #if ENABLE_INPUT_SYSTEM return lookAction.ReadValue (); #else return Vector2.zero; #endif } }