50 lines
1.3 KiB
C#
50 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; }
|
|
public bool blockedInput { get; set; }
|
|
|
|
private Vector2 _dragInput;
|
|
|
|
private GameInputAction action;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if(action == null) action = new GameInputAction();
|
|
action.Enable();
|
|
action.Player.SetCallbacks(this);
|
|
blockedInput = false;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
action.Player.Disable();
|
|
}
|
|
|
|
public void OnDrag(InputAction.CallbackContext context)
|
|
{
|
|
if (blockedInput) return;
|
|
dragInput = context.ReadValue<Vector2>();
|
|
|
|
}
|
|
|
|
public void OnMouseClicked(InputAction.CallbackContext context)
|
|
{
|
|
if (blockedInput) return;
|
|
isMouseButtonPressed = context.ReadValue<float>() == 1 ? true : false;
|
|
}
|
|
}
|