using UnityEngine; using Unheimlich.Data.DetectiveBoard; using Unheimlich.Managers; namespace Unheimlich.Handlers.DetectiveBoard { /// /// 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. /// 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(); } } /// /// Unlocks the associated clue. Can be called from external scripts, events, or animations. /// 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!"); } } /// /// Resets the unlock state (useful for testing). /// public void ResetUnlock() { _hasUnlocked = false; } public event System.Action OnClueUnlocked; } }