Added: unity project for SOLID
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Solid.Interfaces;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
public class PlayerInput : MonoBehaviour, IInput
|
||||
{
|
||||
[Header("Inputs")]
|
||||
[SerializeField] private InputActionReference movementInputReference;
|
||||
[SerializeField] private InputActionReference rotationInputReference;
|
||||
[SerializeField] private InputActionReference fireInputReference;
|
||||
|
||||
private Vector2 _movementInput;
|
||||
private Vector2 _rotationInput;
|
||||
|
||||
public Vector2 MovementInput => _movementInput;
|
||||
public Vector2 RotationInput => _rotationInput;
|
||||
public event Action Fired;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
movementInputReference.action.Enable();
|
||||
rotationInputReference.action.Enable();
|
||||
fireInputReference.action.Enable();
|
||||
fireInputReference.action.performed += OnFireActionPerformed;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
movementInputReference.action.Disable();
|
||||
rotationInputReference.action.Disable();
|
||||
fireInputReference.action.Disable();
|
||||
fireInputReference.action.performed -= OnFireActionPerformed;
|
||||
}
|
||||
|
||||
public void HandleInput()
|
||||
{
|
||||
_movementInput = movementInputReference.action.ReadValue<Vector2>();
|
||||
_rotationInput = rotationInputReference.action.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
private void OnFireActionPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
Fired?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user