files arranged using assembly defn
This commit is contained in:
61
Assets/DarkMatter/Code/Core/Data/InputReaderSO.cs
Normal file
61
Assets/DarkMatter/Code/Core/Data/InputReaderSO.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
[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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user