Files
Hasebe/Assets/Code/OfficeGame/Player/PlayerControlsProvider.cs
T
2026-09-24 20:49:06 +03:00

50 lines
1.7 KiB
C#

using Code.Game.Gameplay.Player;
using Code.Infrastructure.Input;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.Game.Cleaning.Player
{
public class PlayerControlsProvider : MonoBehaviour
{
[SerializeField] private PlayerMovementController playerMovementController;
private IInputService _inputService;
private Vector2 _movementInput;
[Inject]
private void Construct(IInputService inputService)
{
_inputService = inputService;
_inputService.BindActionPerformed((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Movement,
MovementPerformed);
_inputService.BindActionCancelled((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Movement,
MovementCancelled);
}
private void MovementCancelled(InputAction.CallbackContext obj) => _movementInput = Vector2.zero;
private void MovementPerformed(InputAction.CallbackContext obj) => _movementInput = obj.ReadValue<Vector2>();
private void Update()
{
var inputs = new PlayerCharacterInputs()
{
MoveAxisForward = _movementInput.y,
MoveAxisRight = _movementInput.x
};
playerMovementController.SetInputs(ref inputs);
}
private void OnDestroy()
{
_inputService.UnbindActionPerformed((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Movement,
MovementPerformed);
_inputService.UnbindActionCancelled((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Movement,
MovementCancelled);
}
}
}