50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Management
|
|
{
|
|
public class InputRouter : MonoBehaviour
|
|
{
|
|
public event Action<bool> OnInteract;
|
|
private static InputRouter _instance;
|
|
private PlayerInput _playerInput;
|
|
private InputAction _interactAction;
|
|
|
|
private void Awake()
|
|
{
|
|
if (_instance != null && _instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
_playerInput = GetComponent<PlayerInput>();
|
|
_playerInput.actions.Disable();
|
|
EnableGameActions();
|
|
}
|
|
|
|
public void EnableGameActions()
|
|
{
|
|
_playerInput.SwitchCurrentActionMap("Player");
|
|
|
|
_interactAction = _playerInput.actions.FindAction("Interact", true);
|
|
_interactAction.Enable();
|
|
|
|
_interactAction.performed += HandleInteraction;
|
|
_interactAction.canceled += HandleInteraction;
|
|
|
|
}
|
|
|
|
public void EnableUIActions()
|
|
{
|
|
_playerInput.SwitchCurrentActionMap("UI");
|
|
}
|
|
|
|
private void HandleInteraction(InputAction.CallbackContext context)
|
|
{
|
|
OnInteract?.Invoke(context.performed);
|
|
}
|
|
}
|
|
}
|