Hallucination system

This commit is contained in:
Ferlat Thibaud
2026-03-16 17:06:47 +01:00
parent 10faf74405
commit 0d968f75ab
44 changed files with 2860 additions and 909 deletions
@@ -1,105 +1,98 @@
using UnityEngine;
using Unheimlich.Core.Events;
using Unheimlich.Features.DetectiveBoard.Data;
using Unheimlich.Features.DetectiveBoard;
namespace Unheimlich.Features.DetectiveBoard
{
/// <summary>
/// Generic trigger to unlock clues on the detective board.
/// Can be triggered by any game event: dialogue, object interaction, audio cue, hallucination, etc.
/// Simply call UnlockClue() when the trigger condition is met.
/// Unlocks a clue on the detective board.
/// Can be driven by an optional GameEventTrigger on the same GameObject,
/// or called directly via UnlockClue() from any external script or UnityEvent.
/// </summary>
public class ClueUnlockTrigger : MonoBehaviour
{
[Header("Clue Configuration")]
[Tooltip("The clue data to unlock when triggered")]
[SerializeField] private ClueData _clueToUnlock;
[Header("Trigger Settings")]
[Tooltip("Automatically unlock on Start()")]
[Header("Auto Trigger")]
[Tooltip("Unlock automatically on Start()")]
[SerializeField] private bool _unlockOnStart;
[Tooltip("Unlock when this GameObject is enabled")]
[SerializeField] private bool _unlockOnEnable;
[Tooltip("Delay before unlocking (useful for sequencing)")]
[Tooltip("Delay in seconds before unlocking (only with Unlock On Start)")]
[SerializeField] private float _unlockDelay;
[Tooltip("Show debug messages")]
[Tooltip("Prevent unlocking more than once")]
[SerializeField] private bool _unlockOnlyOnce = true;
[Header("Debug")]
[SerializeField] private bool _debugMode;
private GameEventTrigger _eventTrigger;
private bool _hasUnlocked;
/// <summary>Raised after the clue has been successfully unlocked.</summary>
public event System.Action OnClueUnlocked;
private void Awake()
{
// Optional composition with GameEventTrigger
_eventTrigger = GetComponent<GameEventTrigger>();
if (_eventTrigger != null)
_eventTrigger.OnTriggered += UnlockClue;
}
private void Start()
{
if (_unlockOnStart)
{
UnlockClue();
if (_unlockDelay > 0f)
Invoke(nameof(UnlockClue), _unlockDelay);
else
UnlockClue();
}
}
private void OnEnable()
private void OnDestroy()
{
if (_unlockOnEnable && !_hasUnlocked)
{
UnlockClue();
}
if (_eventTrigger != null)
_eventTrigger.OnTriggered -= UnlockClue;
}
/// <summary>
/// Unlocks the associated clue. Can be called from external scripts, events, or animations.
/// Unlocks the associated clue. Can be called directly from external scripts or UnityEvents.
/// </summary>
public void UnlockClue()
{
if (_hasUnlocked)
{
if (_debugMode)
Debug.LogWarning($"[ClueUnlockTrigger] Clue '{_clueToUnlock?.Title}' already unlocked!");
if (_unlockOnlyOnce && _hasUnlocked)
return;
}
if (_clueToUnlock == null)
{
Debug.LogError("[ClueUnlockTrigger] No clue data assigned!");
Debug.LogError("[ClueUnlockTrigger] No clue data assigned!", this);
return;
}
if (_unlockDelay > 0f)
if (DetectiveBoardManager.Instance == null)
{
Invoke(nameof(UnlockClueImmediate), _unlockDelay);
}
else
{
UnlockClueImmediate();
Debug.LogError("[ClueUnlockTrigger] DetectiveBoardManager not found!", this);
return;
}
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
_hasUnlocked = true;
if (_debugMode)
Debug.Log($"[ClueUnlockTrigger] Unlocked clue: {_clueToUnlock.Title}", this);
OnClueUnlocked?.Invoke();
}
private void UnlockClueImmediate()
{
if (DetectiveBoardManager.Instance != null)
{
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
_hasUnlocked = true;
if (_debugMode)
Debug.Log($"[ClueUnlockTrigger] Unlocked clue: {_clueToUnlock.Title}");
OnClueUnlocked?.Invoke();
}
else
{
Debug.LogError("[ClueUnlockTrigger] DetectiveBoardManager not found!");
}
}
/// <summary>
/// Resets the unlock state (useful for testing).
/// </summary>
/// <summary>Resets the unlock state so the clue can be unlocked again.</summary>
public void ResetUnlock()
{
_hasUnlocked = false;
CancelInvoke(nameof(UnlockClue));
}
public event System.Action OnClueUnlocked;
}
}