58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
[CreateAssetMenu(fileName = "InputReader", menuName = "Scriptable Objects/InputReader")]
|
|
public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActions
|
|
{
|
|
public Action<Vector2> OnDragValueChanged;
|
|
public bool isBlocked { get; set;}
|
|
|
|
public Vector2 _dragInput;
|
|
public Vector2 dragInput
|
|
{
|
|
get=> _dragInput;
|
|
private set
|
|
{
|
|
|
|
_dragInput = value;
|
|
OnDragValueChanged?.Invoke(_dragInput);
|
|
}
|
|
}
|
|
|
|
public float clickInput { get; private set; }
|
|
|
|
public bool isclicked {get; private set; }
|
|
|
|
private GameInput inputActions;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if(inputActions==null)
|
|
{
|
|
inputActions = new GameInput();
|
|
inputActions.Player.SetCallbacks(this);
|
|
}
|
|
isBlocked = false;
|
|
inputActions.Enable();
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
inputActions?.Player.Disable();
|
|
}
|
|
|
|
public void OnDrag(InputAction.CallbackContext context)
|
|
{ if (isBlocked) { Debug.Log("InputBlocked"); return; }
|
|
dragInput = context.ReadValue<Vector2>();
|
|
}
|
|
|
|
public void OnClick(InputAction.CallbackContext context)
|
|
{
|
|
if(isBlocked) return;
|
|
clickInput = context.ReadValue<float>();
|
|
isclicked = clickInput == 1? true : false;
|
|
Debug.Log(isclicked);
|
|
}
|
|
}
|