48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
using Solid.Interfaces;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Solid
|
|
{
|
|
public class PlayerInput : MonoBehaviour, IInput
|
|
{
|
|
[SerializeField] private InputActionReference _movementInputAction;
|
|
[SerializeField] private InputActionReference _rotationInputAction;
|
|
[SerializeField] private InputActionReference _fireInputAction;
|
|
|
|
private Vector2 _movement;
|
|
private Vector2 _rotation;
|
|
|
|
public Vector2 Movement => _movement;
|
|
public Vector2 Rotation => _rotation;
|
|
public event Action Fired;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_movementInputAction.action.Enable();
|
|
_rotationInputAction.action.Enable();
|
|
_fireInputAction.action.performed += OnFireActionPerformed;
|
|
_fireInputAction.action.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_movementInputAction.action.Disable();
|
|
_rotationInputAction.action.Disable();
|
|
_fireInputAction.action.Disable();
|
|
_fireInputAction.action.performed -= OnFireActionPerformed;
|
|
}
|
|
|
|
public void HandleInput()
|
|
{
|
|
_movement = _movementInputAction.action.ReadValue<Vector2>();
|
|
_rotation = _rotationInputAction.action.ReadValue<Vector2>();
|
|
}
|
|
|
|
protected virtual void OnFireActionPerformed(InputAction.CallbackContext ctx)
|
|
{
|
|
Fired?.Invoke();
|
|
}
|
|
}
|
|
} |