64 lines
1.2 KiB
C#
64 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.PlayerLoop;
|
|
|
|
[DefaultExecutionOrder(-100)]
|
|
public class PlayerInputHandler : MonoBehaviour
|
|
{
|
|
public event EventHandler OnJumpTrigger;
|
|
public float MoveAxis { get; private set; }
|
|
|
|
private GameInputs _input;
|
|
private bool _isReadyToClear;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
_input = new GameInputs();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_input.Player.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_input.Player.Disable();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_input.Player.Jump.performed += (InputAction.CallbackContext obj) => OnJumpTrigger?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
ClearInput();
|
|
ProcessInput();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
_isReadyToClear = true;
|
|
}
|
|
|
|
private void ProcessInput()
|
|
{
|
|
MoveAxis = _input.Player.Movement.ReadValue<Vector2>().x;
|
|
}
|
|
|
|
private void ClearInput()
|
|
{
|
|
if (!_isReadyToClear)
|
|
return;
|
|
|
|
MoveAxis = 0f;
|
|
|
|
_isReadyToClear = false;
|
|
}
|
|
}
|