|
|
|
|
|
|
using UnityEngine; |
|
|
|
#if ENABLE_INPUT_SYSTEM
|
|
|
|
using UnityEngine.InputSystem; |
|
|
|
using UnityEngine.InputSystem.Controls; |
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace GameplayIngredients.Controllers |
|
|
|
{ |
|
|
|
|
|
|
[Header("Movement")] |
|
|
|
#if ENABLE_INPUT_SYSTEM && ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
public bool preferLegacyInput; |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLE_INPUT_SYSTEM
|
|
|
|
[Header("Input System Package")] |
|
|
|
public InputAction move; |
|
|
|
public InputAction look; |
|
|
|
public InputAction jump; |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
[Header("Legacy Input")] |
|
|
|
|
|
|
|
[Header("Look")] |
|
|
|
|
|
|
|
[Header("Buttons")] |
|
|
|
|
|
|
|
#endif
|
|
|
|
public override Vector2 Look => m_Look; |
|
|
|
public override Vector2 Movement => m_Movement; |
|
|
|
|
|
|
|
|
|
|
Vector2 m_Look; |
|
|
|
ButtonState m_Jump; |
|
|
|
|
|
|
|
ButtonState m_Jump; |
|
|
|
private void Reset() |
|
|
|
{ |
|
|
|
#if ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
InitializeValuesLegacy(); |
|
|
|
#endif
|
|
|
|
#if ENABLE_INPUT_SYSTEM
|
|
|
|
InitializeValuesNIS(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
#if ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
[ContextMenu("Initialize Values (Legacy Input)")] |
|
|
|
void InitializeValuesLegacy() |
|
|
|
{ |
|
|
|
MovementHorizontalAxis = "Horizontal"; |
|
|
|
MovementVerticalAxis = "Vertical"; |
|
|
|
LookHorizontalAxis = "Mouse X"; |
|
|
|
LookVerticalAxis = "Mouse Y"; |
|
|
|
JumpButton = "Jump"; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#if ENABLE_INPUT_SYSTEM
|
|
|
|
[ContextMenu("Initialize Values (Input System Package)")] |
|
|
|
void InitializeValuesNIS() |
|
|
|
{ |
|
|
|
move = new InputAction("Left Stick", InputActionType.Value, "<Gamepad>/Left Stick"); |
|
|
|
move.AddCompositeBinding("2DVector") |
|
|
|
.With("Up", "<Keyboard>/w") |
|
|
|
.With("Down", "<Keyboard>/s") |
|
|
|
.With("Left", "<Keyboard>/a") |
|
|
|
.With("Right", "<Keyboard>/d"); |
|
|
|
|
|
|
|
look = new InputAction("Right Stick", InputActionType.Value, "<Gamepad>/Right Stick"); |
|
|
|
look.AddBinding("<Pointer>/Delta") |
|
|
|
.WithProcessor("ScaleVector2(x=0.1,y=0.1)"); |
|
|
|
jump = new InputAction("Jump", InputActionType.Button, "<Gamepad>/Button South"); |
|
|
|
jump.AddBinding("<Keyboard>/space"); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
m_Movement = new Vector2(Input.GetAxis(MovementHorizontalAxis), Input.GetAxis(MovementVerticalAxis)); |
|
|
|
m_Look = new Vector2(Input.GetAxis(LookHorizontalAxis), Input.GetAxis(LookVerticalAxis)); |
|
|
|
m_Jump = GetButtonState(JumpButton); |
|
|
|
#if ENABLE_INPUT_SYSTEM && ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
if(preferLegacyInput) |
|
|
|
#endif
|
|
|
|
#if ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
{ |
|
|
|
m_Movement = new Vector2(Input.GetAxis(MovementHorizontalAxis), Input.GetAxis(MovementVerticalAxis)); |
|
|
|
m_Look = new Vector2(Input.GetAxis(LookHorizontalAxis), Input.GetAxis(LookVerticalAxis)); |
|
|
|
m_Jump = GetButtonState(JumpButton); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#if ENABLE_INPUT_SYSTEM && ENABLE_LEGACY_INPUT_MANAGER
|
|
|
|
else |
|
|
|
#endif
|
|
|
|
#if ENABLE_INPUT_SYSTEM
|
|
|
|
{ |
|
|
|
if (!move.enabled) |
|
|
|
move.Enable(); |
|
|
|
if(!look.enabled) |
|
|
|
look.Enable(); |
|
|
|
if(!jump.enabled) |
|
|
|
jump.Enable(); |
|
|
|
|
|
|
|
m_Movement = move.ReadValue<Vector2>(); |
|
|
|
m_Look = look.ReadValue<Vector2>(); |
|
|
|
m_Jump = GetButtonControlState(jump.activeControl as ButtonControl); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |