95 lines
2.7 KiB
C#
95 lines
2.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Unheimlich.Managers
|
|
{
|
|
/// <summary>
|
|
/// Centralizes Input System handling for the player.
|
|
/// Manages input state, action references, and global input enable/disable functionality.
|
|
/// </summary>
|
|
[RequireComponent(typeof(PlayerInput))]
|
|
public class PlayerInputManager : MonoBehaviour
|
|
{
|
|
public static PlayerInputManager Instance { get; private set; }
|
|
|
|
[Header("Input Values (Read only)")]
|
|
public Vector2 MoveInput;
|
|
public Vector2 LookInput;
|
|
public InputActionReference JumpAction;
|
|
public InputActionReference InteractAction;
|
|
|
|
public static bool IsInputEnabled { get; private set; } = true;
|
|
public static bool IsLookingEnabled { get; private set; } = true;
|
|
|
|
private InputActionMap _playerActionMap;
|
|
private InputAction _lookAction;
|
|
private InputAction _interactAction;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
Instance = this;
|
|
|
|
IsInputEnabled = true;
|
|
|
|
PlayerInput playerInput = GetComponent<PlayerInput>();
|
|
playerInput.actions.Enable();
|
|
|
|
_playerActionMap = playerInput.actions.FindActionMap("Player");
|
|
_lookAction = _playerActionMap.FindAction("Look");
|
|
_interactAction = _playerActionMap.FindAction("Interact");
|
|
|
|
JumpAction.action.Enable();
|
|
InteractAction.action.Enable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Globally toggles player input on/off. When disabled, only look and interact actions remain active.
|
|
/// Used during dialogues, inspections, or UI interactions.
|
|
/// </summary>
|
|
public static void ToggleInput(bool enable)
|
|
{
|
|
if (Instance == null) return;
|
|
|
|
IsInputEnabled = enable;
|
|
|
|
if (enable)
|
|
{
|
|
IsLookingEnabled = true;
|
|
Instance._playerActionMap.Enable();
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
}
|
|
else
|
|
{
|
|
Instance._playerActionMap.Disable();
|
|
Instance._lookAction.Enable();
|
|
Instance._interactAction.Enable();
|
|
IsLookingEnabled = false;
|
|
}
|
|
}
|
|
|
|
public void OnMove(InputAction.CallbackContext context)
|
|
{
|
|
MoveInput = context.ReadValue<Vector2>();
|
|
}
|
|
|
|
public void Look(InputAction.CallbackContext context)
|
|
{
|
|
LookInput = context.ReadValue<Vector2>();
|
|
}
|
|
|
|
public void OnJump(InputAction.CallbackContext context)
|
|
{
|
|
}
|
|
|
|
public void OnInteract(InputAction.CallbackContext context)
|
|
{
|
|
}
|
|
}
|
|
}
|