Commit 1
This commit is contained in:
89
Assets/Scripts/Player Controller/InputReader.cs
Normal file
89
Assets/Scripts/Player Controller/InputReader.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace OnlyScove.Scripts
|
||||
{
|
||||
public class InputReader : MonoBehaviour
|
||||
{
|
||||
// Continuous Inputs
|
||||
public virtual Vector2 MoveInput { get; protected set; }
|
||||
public virtual Vector2 LookInput { get; protected set; }
|
||||
public virtual Vector2 ScrollInput { get; protected set; }
|
||||
public virtual bool IsSprintHeld { get; protected set; } // Left Shift
|
||||
public virtual bool IsAttackHeld { get; protected set; } // Left Mouse Button
|
||||
|
||||
// One-shot Events
|
||||
public event Action OnJumpEvent; // Space
|
||||
public event Action OnDodgeEvent; // Right Mouse Button (RMB)
|
||||
public event Action OnAttackEvent; // Left Mouse Button (LMB)
|
||||
public event Action OnCrouchEvent; // C Key
|
||||
public event Action OnInteractEvent; // E Key
|
||||
public event Action OnNextInteractEvent; // R Key
|
||||
public event Action OnPreviousInteractEvent; // Q Key
|
||||
|
||||
public void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
OnAttackEvent?.Invoke();
|
||||
IsAttackHeld = true;
|
||||
}
|
||||
if (context.canceled)
|
||||
{
|
||||
IsAttackHeld = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
MoveInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnLook(InputAction.CallbackContext context)
|
||||
{
|
||||
LookInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnScroll(InputAction.CallbackContext context)
|
||||
{
|
||||
ScrollInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnSprint(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) IsSprintHeld = true;
|
||||
if (context.canceled) IsSprintHeld = false;
|
||||
}
|
||||
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnJumpEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void OnDodgeOrThrust(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnDodgeEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void OnCrouch(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnCrouchEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void OnInteract(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnInteractEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void OnNext(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnNextInteractEvent?.Invoke();
|
||||
}
|
||||
|
||||
public void OnPrevious(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed) OnPreviousInteractEvent?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user