Integration of the octo input system and centralization of player values

This commit is contained in:
2026-02-17 17:29:27 +01:00
parent 7b48e385b2
commit 79da2e5722
38 changed files with 2831 additions and 673 deletions
@@ -10,14 +10,12 @@ namespace Unheimlich.Managers
{
/// <summary>
/// Manages gaze-based focus detection for dialogue choices using raycasts.
/// Handles progressive focus timers, aim assist integration, visual feedback,
/// and automatic choice selection when player maintains focus for a duration.
/// </summary>
public class DialogueFocusSystem
{
private readonly DialogueManager _manager;
private readonly Camera _mainCamera;
private readonly PlayerLook _playerLook;
private readonly CameraEffects _cameraEffects;
private ChoiceFocusHandler _currentFocusedHandler;
private float _focusTimer = 0f;
@@ -38,7 +36,7 @@ namespace Unheimlich.Managers
public DialogueFocusSystem(
DialogueManager manager,
Camera mainCamera,
PlayerLook playerLook,
CameraEffects cameraEffects,
LayerMask choiceLayer,
float focusRange,
float focusTime,
@@ -49,7 +47,7 @@ namespace Unheimlich.Managers
{
_manager = manager;
_mainCamera = mainCamera;
_playerLook = playerLook;
_cameraEffects = cameraEffects;
_choiceLayer = choiceLayer;
_focusRange = focusRange;
_focusTime = focusTime;
@@ -101,8 +99,8 @@ namespace Unheimlich.Managers
{
hitHandler = hit.collider.GetComponent<ChoiceFocusHandler>();
if (_playerLook != null && hitHandler != null)
_playerLook.ApplyAimAssist(hit.collider.bounds.center);
if (_cameraEffects != null && hitHandler != null)
_cameraEffects.ApplyAimAssist(hit.collider.bounds.center);
}
if (hitHandler != _currentFocusedHandler)
@@ -121,8 +119,8 @@ namespace Unheimlich.Managers
_focusTimer = 0f;
_retentionTimer = _focusRetentionTime;
if (_playerLook != null)
_playerLook.LockAim(true);
if (_cameraEffects != null)
_cameraEffects.LockAim(true);
ApplyUnfocusEffectToOthers(hitHandler);
@@ -152,11 +150,11 @@ namespace Unheimlich.Managers
DialogueAnimationSettings currentSettings = _manager.CurrentAnimationSettings;
bool shouldShake = currentSettings == null || currentSettings.EnableCameraShakeOnFocus;
if (shouldShake && _playerLook != null)
if (shouldShake && _cameraEffects != null)
{
float shakeIntensity = currentSettings != null ? currentSettings.CameraShakeIntensity : _fallbackShakeIntensity;
float shakeSmoothness = currentSettings != null ? currentSettings.CameraShakeSmoothness : 10f;
_playerLook.Shake(progress / shakeIntensity, shakeSmoothness);
_cameraEffects.ShakeCamera(progress / shakeIntensity, shakeSmoothness);
}
if (_focusTimer >= _focusTime)
@@ -183,8 +181,8 @@ namespace Unheimlich.Managers
selectedHandler.ResetFeedback(_recoveryDuration);
if (_playerLook != null)
_playerLook.LockAim(false);
if (_cameraEffects != null)
_cameraEffects.LockAim(false);
}
}
else if (_currentFocusedHandler != null && _retentionTimer <= 0f)
@@ -202,8 +200,8 @@ namespace Unheimlich.Managers
ResetAnimationTimers();
if (_playerLook != null)
_playerLook.LockAim(false);
if (_cameraEffects != null)
_cameraEffects.LockAim(false);
}
}
@@ -6,6 +6,7 @@ using Unheimlich.Gameplay.Player;
using Unheimlich.UI;
using Unheimlich.Interactions.Dialogues;
using System.Collections.Generic;
using InputManager = Unheimlich.Managers.InputManager;
namespace Unheimlich.Managers
{
@@ -41,7 +42,6 @@ namespace Unheimlich.Managers
private DialogueFocusSystem _focusSystem;
private Camera _mainCamera;
private PlayerLook _playerLook;
private DialogueAnimationSettings _currentAnimationSettings;
private DialogueUI _activeDialogueUI;
private Transform _currentChoiceAnchor;
@@ -57,13 +57,12 @@ namespace Unheimlich.Managers
private void Start()
{
_playerLook = PlayerLook.Instance;
_mainCamera = Camera.main;
_focusSystem = new DialogueFocusSystem(
this,
_mainCamera,
_playerLook,
PlayerController.Instance?.CameraEffects,
_choiceLayer,
_focusRange,
_focusTime,
@@ -107,7 +106,7 @@ namespace Unheimlich.Managers
}
}
var interactAction = PlayerInputManager.GetInteractAction();
var interactAction = InputManager.GetInteractAction();
if (interactAction != null && interactAction.WasPressedThisFrame())
{
EndDialogue();
@@ -0,0 +1,267 @@
using UnityEngine;
using OctoCore;
using OctoCore.Inputs;
using Unheimlich.Core;
namespace Unheimlich.Managers
{
/// <summary>
/// Unified input manager wrapping OctoCore inputs with Unheimlich-specific contexts.
/// Replaces the old PlayerInputManager while keeping context system (Normal, Dialogue, Listening).
/// </summary>
public class InputManager : Singleton<InputManager>
{
public enum InputContext
{
Normal, // All inputs enabled
Dialogue, // Only look and interact
Listening, // Only look and diapason
Inspection // Only look and interact (for item inspection)
}
[Header("Current State")]
[SerializeField] private InputContext _currentContext = InputContext.Normal;
// Public access to current context
public static InputContext CurrentContext => Instance ? Instance._currentContext : InputContext.Normal;
// Input values (cached for compatibility)
public static Vector2 MoveInput { get; private set; }
public static Vector2 LookInput { get; private set; }
// Legacy compatibility
public static bool IsInputEnabled => CurrentContext == InputContext.Normal;
public static bool IsLookingEnabled => CurrentContext != InputContext.Dialogue;
protected override void OnAwake()
{
// Try to subscribe, will retry in Start if needed
SubscribeAllInputs();
SetContext(InputContext.Normal);
}
private void Start()
{
Debug.Log("[InputManager] Start() called");
if (OctoCore.OctoCore.Instance == null)
{
Debug.LogError("[InputManager] OctoCore.Instance is NULL!");
return;
}
Debug.Log("[InputManager] OctoCore.Instance exists");
if (OctoCore.OctoCore.Instance.Inputs == null)
{
Debug.LogError("[InputManager] OctoCore.Instance.Inputs is NULL!");
return;
}
Debug.Log("[InputManager] OctoCore.Instance.Inputs exists");
// Ensure we're subscribed
SubscribeAllInputs();
Debug.Log("[InputManager] Initialized and subscribed to OctoCore inputs.");
}
private void OnDestroy()
{
UnsubscribeAllInputs();
}
// Subscribe to OctoCore inputs
private void SubscribeAllInputs()
{
if (OctoCore.OctoCore.Instance == null) return;
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Move, OnMove);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Look, OnLook);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Jump, OnJump);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Interact, OnInteract);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Diapason, OnDiapason);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Fire, OnFire);
OctoCore.OctoCore.Instance.Inputs.SubscribeAction(OctoActions.Player_Exit, OnExit);
}
private void UnsubscribeAllInputs()
{
if (OctoCore.OctoCore.Instance == null) return;
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Move, OnMove);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Look, OnLook);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Jump, OnJump);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Interact, OnInteract);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Diapason, OnDiapason);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Fire, OnFire);
OctoCore.OctoCore.Instance.Inputs.UnsubscribeAction(OctoActions.Player_Exit, OnExit);
}
/// <summary>
/// Sets input context and handles cursor/component state
/// </summary>
public static void SetContext(InputContext context)
{
if (Instance == null) return;
Instance._currentContext = context;
switch (context)
{
case InputContext.Normal:
// All inputs active
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
break;
case InputContext.Dialogue:
// Only look and interact (movement disabled)
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
break;
case InputContext.Listening:
// Only look, diapason, fire, exit (movement disabled)
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
break;
case InputContext.Inspection:
// Only look and interact (for item inspection, movement disabled)
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
break;
}
}
// Legacy compatibility
public static void ToggleInput(bool enable)
{
SetContext(enable ? InputContext.Normal : InputContext.Dialogue);
}
// Input callbacks - cache values and filter by context
private void OnMove(Vector2 value)
{
MoveInput = _currentContext == InputContext.Normal ? value : Vector2.zero;
}
private void OnLook(Vector2 value)
{
LookInput = value; // Look enabled in all contexts
}
private void OnJump()
{
if (_currentContext != InputContext.Normal) return;
// Broadcast jump event if needed
}
private void OnInteract()
{
if (_currentContext == InputContext.Listening) return;
// Broadcast interact event
}
private void OnDiapason()
{
if (_currentContext == InputContext.Dialogue) return;
// Broadcast diapason event
}
private void OnFire()
{
if (_currentContext != InputContext.Listening) return;
// Broadcast fire event
}
private void OnExit()
{
if (_currentContext != InputContext.Listening) return;
// Broadcast exit event
}
// Public accessors for backward compatibility
public static Vector2 GetMoveInput() => MoveInput;
public static Vector2 GetLookInput() => LookInput;
// Action accessors for direct button checks
public static UnityEngine.InputSystem.InputAction GetMoveAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Move" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
public static UnityEngine.InputSystem.InputAction GetDiapasonAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Diapason" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
public static UnityEngine.InputSystem.InputAction GetInteractAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Interact" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
public static UnityEngine.InputSystem.InputAction GetFireAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Fire" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
public static UnityEngine.InputSystem.InputAction GetExitAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Exit" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
public static UnityEngine.InputSystem.InputAction GetLookAction()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return null;
foreach (var actionInfo in asset)
{
if (actionInfo.Name == "Look" && actionInfo.Reference != null)
return actionInfo.Reference.action;
}
return null;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e340839b22a784542ba8afdfde612c2e
@@ -1,179 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
using Unheimlich.Core;
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 : Singleton<PlayerInputManager>
{
/// <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)
}
[Header("Input Values (Read only)")]
public Vector2 MoveInput;
public Vector2 LookInput;
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 _moveAction;
private InputAction _lookAction;
private InputAction _jumpAction;
private InputAction _interactAction;
private InputAction _diapasonAction;
private InputAction _fireAction;
private InputAction _exitAction;
private PlayerMovement _playerMovement;
private PlayerLook _playerLook;
private CameraHeadBob _headBob;
protected override void OnAwake()
{
IsInputEnabled = true;
PlayerInput playerInput = GetComponent<PlayerInput>();
playerInput.actions.Enable();
_playerActionMap = playerInput.actions.FindActionMap("Player");
_moveAction = _playerActionMap.FindAction("Move");
_lookAction = _playerActionMap.FindAction("Look");
_jumpAction = _playerActionMap.FindAction("Jump");
_interactAction = _playerActionMap.FindAction("Interact");
_diapasonAction = _playerActionMap.FindAction("Diapason");
_fireAction = _playerActionMap.FindAction("Fire");
_exitAction = _playerActionMap.FindAction("Exit");
_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();
if (Instance._fireAction != null)
Instance._fireAction.Enable();
if (Instance._exitAction != null)
Instance._exitAction.Enable();
Instance.SetComponentsEnabled(false, false, true);
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)
{
SetContext(enable ? InputContext.Normal : InputContext.Dialogue);
}
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)
{
}
public void OnDiapason(InputAction.CallbackContext context)
{
}
public void OnFire(InputAction.CallbackContext context)
{
}
public void OnExit(InputAction.CallbackContext context)
{
}
/// <summary>
/// Provides public access to input actions for other systems.
/// </summary>
public static InputAction GetMoveAction() => Instance?._moveAction;
public static InputAction GetLookAction() => Instance?._lookAction;
public static InputAction GetJumpAction() => Instance?._jumpAction;
public static InputAction GetInteractAction() => Instance?._interactAction;
public static InputAction GetDiapasonAction() => Instance?._diapasonAction;
public static InputAction GetFireAction() => Instance?._fireAction;
public static InputAction GetExitAction() => Instance?._exitAction;
}
}
@@ -1,13 +0,0 @@
fileFormatVersion: 2
guid: 860eff61af1c75243b697035c7b7fc83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- JumpAction: {fileID: -2099379676528639254, guid: 052faaac586de48259a63d0c4782560b, type: 3}
- InteractAction: {fileID: 1781555164194001046, guid: 052faaac586de48259a63d0c4782560b, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: