Files
HelixJump/Assets/Scripts/Input/InputReaderSO.cs
2025-12-15 18:34:06 -08:00

56 lines
1.3 KiB
C#

using System;
using UnityEngine;
using UnityEngine.InputSystem;
[CreateAssetMenu(fileName = "InputReaderSO", menuName = "Scriptable Objects/InputReaderSO")]
public class InputReaderSO : ScriptableObject, GameInputAction.IPlayerActions , IInputReader
{
public event Action<Vector2> OnDragValueChanged;
public Vector2 dragInput {
get => _dragInput;
private set {
_dragInput = value;
OnDragValueChanged?.Invoke(_dragInput);
}
}
public bool isMouseButtonPressed { get;private set; }
private bool blockedInput = false;
private Vector2 _dragInput;
private GameInputAction action;
private void OnEnable()
{
if(action == null) action = new GameInputAction();
action.Enable();
action.Player.SetCallbacks(this);
isMouseButtonPressed= false;
}
private void OnDisable()
{
action.Player.Disable();
}
public void OnDrag(InputAction.CallbackContext context)
{
dragInput = context.ReadValue<Vector2>();
}
public void OnMouseClicked(InputAction.CallbackContext context)
{
isMouseButtonPressed = context.ReadValue<float>() == 1 ? true : false;
}
public void LockInput()
{
action.Player.Disable();
}
public void UnlockInput()
{
action.Player.Enable();
}
}