Fully functional diapason + upgrade input manager
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
|
||||
namespace Unheimlich.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Centralizes Input System handling for the player.
|
||||
/// Manages input state, action references, and global input enable/disable functionality.
|
||||
/// Supports different input contexts (Normal, Dialogue, Listening) to control which inputs are active.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(PlayerInput))]
|
||||
public class PlayerInputManager : MonoBehaviour
|
||||
{
|
||||
public static PlayerInputManager Instance { get; private set; }
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines different input contexts that control which player actions are enabled.
|
||||
/// </summary>
|
||||
public enum InputContext
|
||||
{
|
||||
Normal, // All inputs enabled (movement, look, jump, interact, diapason)
|
||||
Dialogue, // Only look and interact enabled (for dialogues/UI)
|
||||
Listening // Only look enabled, movement disabled (for diapason camera pan)
|
||||
}
|
||||
|
||||
public static PlayerInputManager Instance { get; private set; }
|
||||
|
||||
[Header("Input Values (Read only)")]
|
||||
public Vector2 MoveInput;
|
||||
@@ -21,12 +33,17 @@ namespace Unheimlich.Managers
|
||||
|
||||
public static bool IsInputEnabled { get; private set; } = true;
|
||||
public static bool IsLookingEnabled { get; private set; } = true;
|
||||
public static InputContext CurrentContext { get; private set; } = InputContext.Normal;
|
||||
|
||||
private InputActionMap _playerActionMap;
|
||||
private InputAction _lookAction;
|
||||
private InputAction _interactAction;
|
||||
private InputAction _diapasonAction;
|
||||
|
||||
private PlayerMovement _playerMovement;
|
||||
private PlayerLook _playerLook;
|
||||
private CameraHeadBob _headBob;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
@@ -50,34 +67,76 @@ namespace Unheimlich.Managers
|
||||
InteractAction.action.Enable();
|
||||
if (DiapasonAction != null)
|
||||
DiapasonAction.action.Enable();
|
||||
|
||||
_playerMovement = GetComponent<PlayerMovement>();
|
||||
_playerLook = GetComponent<PlayerLook>();
|
||||
_headBob = GetComponentInChildren<CameraHeadBob>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the input context, controlling which inputs and player components are active.
|
||||
/// </summary>
|
||||
public static void SetContext(InputContext context)
|
||||
{
|
||||
if (Instance == null) return;
|
||||
|
||||
CurrentContext = context;
|
||||
|
||||
switch (context)
|
||||
{
|
||||
case InputContext.Normal:
|
||||
Instance._playerActionMap.Enable();
|
||||
Instance.SetComponentsEnabled(true, true, true);
|
||||
IsInputEnabled = true;
|
||||
IsLookingEnabled = true;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
break;
|
||||
|
||||
case InputContext.Dialogue:
|
||||
Instance._playerActionMap.Disable();
|
||||
Instance._lookAction.Enable();
|
||||
Instance._interactAction.Enable();
|
||||
if (Instance._diapasonAction != null)
|
||||
Instance._diapasonAction.Enable();
|
||||
Instance.SetComponentsEnabled(false, false, false);
|
||||
IsInputEnabled = false;
|
||||
IsLookingEnabled = false;
|
||||
break;
|
||||
|
||||
case InputContext.Listening:
|
||||
Instance._playerActionMap.Disable();
|
||||
Instance._lookAction.Enable();
|
||||
if (Instance._diapasonAction != null)
|
||||
Instance._diapasonAction.Enable();
|
||||
Instance.SetComponentsEnabled(false, false, false);
|
||||
IsInputEnabled = false;
|
||||
IsLookingEnabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables player movement components.
|
||||
/// </summary>
|
||||
private void SetComponentsEnabled(bool movement, bool look, bool headBob)
|
||||
{
|
||||
if (_playerMovement != null)
|
||||
_playerMovement.enabled = movement;
|
||||
if (_playerLook != null)
|
||||
_playerLook.enabled = look;
|
||||
if (_headBob != null)
|
||||
_headBob.enabled = headBob;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Globally toggles player input on/off. When disabled, only look and interact actions remain active.
|
||||
/// Used during dialogues, inspections, or UI interactions.
|
||||
/// LEGACY: Use SetContext(InputContext.Dialogue) instead.
|
||||
/// </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();
|
||||
if (Instance._diapasonAction != null)
|
||||
Instance._diapasonAction.Enable();
|
||||
IsLookingEnabled = false;
|
||||
}
|
||||
SetContext(enable ? InputContext.Normal : InputContext.Dialogue);
|
||||
}
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
|
||||
Reference in New Issue
Block a user