chore: Project Restructuring & Theatre

This commit is contained in:
Alexandre Coirier
2026-05-13 12:24:48 +02:00
parent 4070916c1f
commit e96d0bf6e6
2145 changed files with 20957 additions and 44792 deletions
@@ -0,0 +1,240 @@
using UnityEngine;
using OctoCore;
using OctoCore.Inputs;
using Unheimlich.Core;
namespace Unheimlich.Core.Input
{
/// <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)
DetectiveBoard // Mouse cursor free, movement disabled
}
[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; }
// Cached InputAction references — populated once during initialization
private static UnityEngine.InputSystem.InputAction _cachedMoveAction;
private static UnityEngine.InputSystem.InputAction _cachedLookAction;
private static UnityEngine.InputSystem.InputAction _cachedInteractAction;
private static UnityEngine.InputSystem.InputAction _cachedDiapasonAction;
private static UnityEngine.InputSystem.InputAction _cachedFireAction;
private static UnityEngine.InputSystem.InputAction _cachedExitAction;
// 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();
CacheAllActions();
SetContext(InputContext.Normal);
}
private void Start()
{
if (OctoCore.OctoCore.Instance == null)
{
Debug.LogError("[InputManager] OctoCore.Instance is NULL!");
return;
}
if (OctoCore.OctoCore.Instance.Inputs == null)
{
Debug.LogError("[InputManager] OctoCore.Instance.Inputs is NULL!");
return;
}
// Ensure we're subscribed and actions are cached
SubscribeAllInputs();
CacheAllActions();
}
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);
}
/// <summary>
/// Caches all InputAction references from OctoCore once at startup to avoid
/// per-frame iteration over the Actions list.
/// </summary>
private void CacheAllActions()
{
var asset = OctoCore.OctoCore.Instance?.Inputs?.Actions;
if (asset == null) return;
_cachedMoveAction = null;
_cachedLookAction = null;
_cachedInteractAction = null;
_cachedDiapasonAction = null;
_cachedFireAction = null;
_cachedExitAction = null;
foreach (var actionInfo in asset)
{
if (actionInfo.Reference == null) continue;
switch (actionInfo.Name)
{
case "Move": _cachedMoveAction = actionInfo.Reference.action; break;
case "Look": _cachedLookAction = actionInfo.Reference.action; break;
case "Interact": _cachedInteractAction = actionInfo.Reference.action; break;
case "Diapason": _cachedDiapasonAction = actionInfo.Reference.action; break;
case "Fire": _cachedFireAction = actionInfo.Reference.action; break;
case "Exit": _cachedExitAction = actionInfo.Reference.action; break;
}
}
}
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;
case InputContext.DetectiveBoard:
// Mouse cursor free for board interaction, movement disabled
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
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 — return pre-cached references, no per-frame allocation
public static UnityEngine.InputSystem.InputAction GetMoveAction() => _cachedMoveAction;
public static UnityEngine.InputSystem.InputAction GetLookAction() => _cachedLookAction;
public static UnityEngine.InputSystem.InputAction GetInteractAction() => _cachedInteractAction;
public static UnityEngine.InputSystem.InputAction GetDiapasonAction() => _cachedDiapasonAction;
public static UnityEngine.InputSystem.InputAction GetFireAction() => _cachedFireAction;
public static UnityEngine.InputSystem.InputAction GetExitAction() => _cachedExitAction;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e340839b22a784542ba8afdfde612c2e