Add detective board

This commit is contained in:
2026-02-10 03:00:41 +01:00
parent d4a728a150
commit b172762d4f
51 changed files with 1502 additions and 92 deletions
@@ -0,0 +1,115 @@
using UnityEngine;
using Unheimlich.Data.DetectiveBoard;
using Unheimlich.Managers;
namespace Unheimlich.Handlers.DetectiveBoard
{
/// <summary>
/// Unlocks a clue when a specific audio source plays or finishes playing.
/// Useful for triggering clues based on environmental sounds, dialogue, or hallucinations.
/// </summary>
[RequireComponent(typeof(AudioSource))]
public class ClueUnlockOnAudio : MonoBehaviour
{
public enum UnlockTrigger
{
OnPlay,
OnFinish,
OnTimeReached
}
[Header("Clue Configuration")]
[Tooltip("The clue to unlock")]
[SerializeField] private ClueData _clueToUnlock;
[Header("Audio Trigger")]
[Tooltip("When to unlock the clue")]
[SerializeField] private UnlockTrigger _trigger = UnlockTrigger.OnPlay;
[Tooltip("Time in seconds to wait before unlocking (only for OnTimeReached)")]
[SerializeField] private float _unlockTime = 1f;
private AudioSource _audioSource;
private bool _hasUnlocked;
private bool _isMonitoring;
private float _currentTime;
private void Awake()
{
_audioSource = GetComponent<AudioSource>();
}
private void OnEnable()
{
if (_audioSource != null && _audioSource.isPlaying)
{
StartMonitoring();
}
}
private void Update()
{
if (!_isMonitoring || _hasUnlocked)
return;
if (_audioSource == null || !_audioSource.isPlaying)
{
if (_trigger == UnlockTrigger.OnFinish && _isMonitoring)
{
UnlockClue();
}
_isMonitoring = false;
return;
}
_currentTime = _audioSource.time;
if (_trigger == UnlockTrigger.OnTimeReached && _currentTime >= _unlockTime)
{
UnlockClue();
}
}
/// <summary>
/// Call this when the audio starts playing.
/// </summary>
public void OnAudioPlay()
{
StartMonitoring();
if (_trigger == UnlockTrigger.OnPlay)
{
UnlockClue();
}
}
private void StartMonitoring()
{
_isMonitoring = true;
_currentTime = 0f;
}
private void UnlockClue()
{
if (_hasUnlocked || _clueToUnlock == null)
return;
if (DetectiveBoardManager.Instance != null)
{
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
_hasUnlocked = true;
Debug.Log($"[ClueUnlockOnAudio] Unlocked clue: {_clueToUnlock.Title} via audio trigger");
}
}
/// <summary>
/// Resets the unlock state.
/// </summary>
public void ResetUnlock()
{
_hasUnlocked = false;
_isMonitoring = false;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fcedba870c1ea9642a272a53148bb933
@@ -0,0 +1,43 @@
using UnityEngine;
using Unheimlich.Data.DetectiveBoard;
using Unheimlich.Interactions.Core;
using Unheimlich.Managers;
namespace Unheimlich.Handlers.DetectiveBoard
{
/// <summary>
/// Unlocks a clue when the player interacts with this object.
/// Extends InteractableBase to integrate with the existing interaction system.
/// </summary>
public class ClueUnlockOnInteraction : InteractableBase
{
[Header("Clue Configuration")]
[Tooltip("The clue to unlock when player interacts")]
[SerializeField] private ClueData _clueToUnlock;
[Tooltip("Only unlock once")]
[SerializeField] private bool _unlockOnlyOnce = true;
private bool _hasUnlocked;
public override void Interact(GameObject interactor)
{
if (_unlockOnlyOnce && _hasUnlocked)
return;
if (_clueToUnlock == null)
{
Debug.LogError("[ClueUnlockOnInteraction] No clue data assigned!");
return;
}
if (DetectiveBoardManager.Instance != null)
{
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
_hasUnlocked = true;
Debug.Log($"[ClueUnlockOnInteraction] Unlocked clue: {_clueToUnlock.Title} via interaction");
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cca584f48d1f0ab429416470fd01d543
@@ -0,0 +1,105 @@
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;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 61b90106a531ea840b670f368e2c8aa9