Files
Ipseity-Demo/Assets/Unheimlich_POC/Scripts/Handlers/DetectiveBoard/ClueUnlockTrigger.cs
T
2026-02-10 03:00:41 +01:00

106 lines
3.1 KiB
C#

using UnityEngine;
using Unheimlich.Data.DetectiveBoard;
using Unheimlich.Managers;
namespace Unheimlich.Handlers.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.
/// </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()")]
[SerializeField] private bool _unlockOnStart;
[Tooltip("Unlock when this GameObject is enabled")]
[SerializeField] private bool _unlockOnEnable;
[Tooltip("Delay before unlocking (useful for sequencing)")]
[SerializeField] private float _unlockDelay;
[Tooltip("Show debug messages")]
[SerializeField] private bool _debugMode;
private bool _hasUnlocked;
private void Start()
{
if (_unlockOnStart)
{
UnlockClue();
}
}
private void OnEnable()
{
if (_unlockOnEnable && !_hasUnlocked)
{
UnlockClue();
}
}
/// <summary>
/// Unlocks the associated clue. Can be called from external scripts, events, or animations.
/// </summary>
public void UnlockClue()
{
if (_hasUnlocked)
{
if (_debugMode)
Debug.LogWarning($"[ClueUnlockTrigger] Clue '{_clueToUnlock?.Title}' already unlocked!");
return;
}
if (_clueToUnlock == null)
{
Debug.LogError("[ClueUnlockTrigger] No clue data assigned!");
return;
}
if (_unlockDelay > 0f)
{
Invoke(nameof(UnlockClueImmediate), _unlockDelay);
}
else
{
UnlockClueImmediate();
}
}
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>
public void ResetUnlock()
{
_hasUnlocked = false;
}
public event System.Action OnClueUnlocked;
}
}