using UnityEngine; using UnityEngine.InputSystem; namespace Unheimlich.Managers { /// /// Centralizes Input System handling for the player. /// Manages input state, action references, and global input enable/disable functionality. /// [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 InputActionReference DiapasonAction; 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 InputAction _diapasonAction; private void Awake() { if (Instance != null && Instance != this) { Destroy(this); return; } Instance = this; IsInputEnabled = true; PlayerInput playerInput = GetComponent(); playerInput.actions.Enable(); _playerActionMap = playerInput.actions.FindActionMap("Player"); _lookAction = _playerActionMap.FindAction("Look"); _interactAction = _playerActionMap.FindAction("Interact"); _diapasonAction = _playerActionMap.FindAction("Diapason"); JumpAction.action.Enable(); InteractAction.action.Enable(); if (DiapasonAction != null) DiapasonAction.action.Enable(); } /// /// Globally toggles player input on/off. When disabled, only look and interact actions remain active. /// Used during dialogues, inspections, or UI interactions. /// 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(); if (Instance._diapasonAction != null) Instance._diapasonAction.Enable(); IsLookingEnabled = false; } } public void OnMove(InputAction.CallbackContext context) { MoveInput = context.ReadValue(); } public void Look(InputAction.CallbackContext context) { LookInput = context.ReadValue(); } public void OnJump(InputAction.CallbackContext context) { } public void OnInteract(InputAction.CallbackContext context) { } public void OnDiapason(InputAction.CallbackContext context) { } } }