Initial commit
This commit is contained in:
49
Assets/Scripts/Input/InputReaderSO.cs
Normal file
49
Assets/Scripts/Input/InputReaderSO.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user