add some extra assets FX and SFX
This commit is contained in:
111
Assets/Game Kit Controller/Scripts/Input/InputAxisWrapper.cs
Normal file
111
Assets/Game Kit Controller/Scripts/Input/InputAxisWrapper.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user