chore: Project Restructuring & Theatre
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core.Audio;
|
||||
using Unheimlich.Features.DetectiveBoard.Data;
|
||||
|
||||
namespace Unheimlich.Features.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// Unlocks a clue when a specific AudioSource plays, finishes, or reaches a timestamp.
|
||||
/// Call OnAudioPlay() from whatever drives the AudioSource to start monitoring.
|
||||
/// </summary>
|
||||
public class ClueUnlockOnAudio : AudioTriggerBase
|
||||
{
|
||||
[Header("Clue Configuration")]
|
||||
[Tooltip("The clue to unlock")]
|
||||
[SerializeField] private ClueData _clueToUnlock;
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
if (_clueToUnlock == null)
|
||||
{
|
||||
Debug.LogError("[ClueUnlockOnAudio] No ClueData assigned!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (DetectiveBoardManager.Instance == null)
|
||||
{
|
||||
Debug.LogError("[ClueUnlockOnAudio] DetectiveBoardManager not found!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
|
||||
|
||||
if (_debugMode)
|
||||
Debug.Log($"[ClueUnlockOnAudio] Unlocked clue '{_clueToUnlock.Title}' on '{_fireCondition}'.", this);
|
||||
}
|
||||
|
||||
/// <summary>Resets the unlock state so the clue can be unlocked again.</summary>
|
||||
public void ResetUnlock() => ResetFired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcedba870c1ea9642a272a53148bb933
|
||||
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Features.DetectiveBoard.Data;
|
||||
using Unheimlich.Core.Interaction;
|
||||
using Unheimlich.Features.DetectiveBoard;
|
||||
using Unheimlich.Features.Items;
|
||||
|
||||
namespace Unheimlich.Features.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// Unlocks a clue when the player interacts with this object.
|
||||
/// Can work standalone (extends InteractableBase) or piggyback on an existing InspectableItem.
|
||||
/// </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;
|
||||
private InspectableItem _inspectableItem;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_inspectableItem = GetComponent<InspectableItem>();
|
||||
}
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
if (_unlockOnlyOnce && _hasUnlocked)
|
||||
{
|
||||
if (_inspectableItem != null)
|
||||
_inspectableItem.Interact();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clueToUnlock == null)
|
||||
{
|
||||
Debug.LogError("[ClueUnlockOnInteraction] No clue data assigned!");
|
||||
if (_inspectableItem != null)
|
||||
_inspectableItem.Interact();
|
||||
return;
|
||||
}
|
||||
|
||||
if (DetectiveBoardManager.Instance != null)
|
||||
{
|
||||
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
|
||||
_hasUnlocked = true;
|
||||
|
||||
}
|
||||
|
||||
if (_inspectableItem != null)
|
||||
{
|
||||
_inspectableItem.Interact();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cca584f48d1f0ab429416470fd01d543
|
||||
@@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core.Events;
|
||||
using Unheimlich.Features.DetectiveBoard.Data;
|
||||
|
||||
namespace Unheimlich.Features.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// 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("Auto Trigger")]
|
||||
[Tooltip("Unlock automatically on Start()")]
|
||||
[SerializeField] private bool _unlockOnStart;
|
||||
|
||||
[Tooltip("Delay in seconds before unlocking (only with Unlock On Start)")]
|
||||
[SerializeField] private float _unlockDelay;
|
||||
|
||||
[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)
|
||||
{
|
||||
if (_unlockDelay > 0f)
|
||||
Invoke(nameof(UnlockClue), _unlockDelay);
|
||||
else
|
||||
UnlockClue();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_eventTrigger != null)
|
||||
_eventTrigger.OnTriggered -= UnlockClue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks the associated clue. Can be called directly from external scripts or UnityEvents.
|
||||
/// </summary>
|
||||
public void UnlockClue()
|
||||
{
|
||||
if (_unlockOnlyOnce && _hasUnlocked)
|
||||
return;
|
||||
|
||||
if (_clueToUnlock == null)
|
||||
{
|
||||
Debug.LogError("[ClueUnlockTrigger] No clue data assigned!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (DetectiveBoardManager.Instance == null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>Resets the unlock state so the clue can be unlocked again.</summary>
|
||||
public void ResetUnlock()
|
||||
{
|
||||
_hasUnlocked = false;
|
||||
CancelInvoke(nameof(UnlockClue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61b90106a531ea840b670f368e2c8aa9
|
||||
@@ -0,0 +1,219 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.World.CameraSystem;
|
||||
using Unheimlich.Features.Player;
|
||||
using Unheimlich.Features.OctoArms;
|
||||
using InputManager = Unheimlich.Core.Input.InputManager;
|
||||
using Unheimlich.Features.DetectiveBoard.UI;
|
||||
using Unheimlich.Features.Dialogue.UI;
|
||||
|
||||
namespace Unheimlich.Features.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls player interaction with the detective board.
|
||||
/// </summary>
|
||||
public class DetectiveBoardController : Singleton<DetectiveBoardController>
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] private float _activationRange = 2f;
|
||||
[SerializeField] private LayerMask _boardLayer;
|
||||
[SerializeField] private CameraPanSettings _playerAlignmentSettings;
|
||||
|
||||
[Header("Virtual Camera")]
|
||||
[SerializeField] private DetectiveBoardVirtualCamera _virtualCamera;
|
||||
|
||||
private bool _isBoardActive;
|
||||
private CameraHeadBob _cameraHeadBob;
|
||||
|
||||
public bool IsBoardActive => _isBoardActive;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_cameraHeadBob = FindFirstObjectByType<CameraHeadBob>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(_virtualCamera == null)
|
||||
_virtualCamera = DetectiveBoardVirtualCamera.Instance;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isBoardActive)
|
||||
{
|
||||
HandleBoardInteraction();
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckForBoardActivation();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForBoardActivation()
|
||||
{
|
||||
if (PlayerController.Instance == null ||
|
||||
PlayerController.Instance.PlayerCamera == null ||
|
||||
DetectiveBoardCanvas.Instance == null)
|
||||
return;
|
||||
|
||||
var camera = PlayerController.Instance.PlayerCamera;
|
||||
var boardTransform = DetectiveBoardCanvas.Instance.transform;
|
||||
|
||||
float distanceToBoard = Vector3.Distance(camera.transform.position, boardTransform.position);
|
||||
if (distanceToBoard > _activationRange)
|
||||
return;
|
||||
|
||||
Ray ray = new Ray(camera.transform.position, camera.transform.forward);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, _activationRange, _boardLayer))
|
||||
{
|
||||
bool isLookingAtBoard = (hit.transform == boardTransform) ||
|
||||
(boardTransform.IsChildOf(hit.transform)) ||
|
||||
(hit.transform.IsChildOf(boardTransform));
|
||||
|
||||
if (isLookingAtBoard)
|
||||
{
|
||||
var interactAction = InputManager.GetInteractAction();
|
||||
if (interactAction != null && interactAction.WasPressedThisFrame())
|
||||
{
|
||||
ActivateBoard();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ActivateBoard()
|
||||
{
|
||||
if (_isBoardActive ||
|
||||
PlayerController.Instance?.PlayerCamera == null ||
|
||||
PlayerController.Instance?.CameraPanController == null ||
|
||||
DetectiveBoardCanvas.Instance == null ||
|
||||
DetectiveBoardVirtualCamera.Instance == null)
|
||||
{
|
||||
Debug.LogError("[DetectiveBoardController] Missing required references!");
|
||||
return;
|
||||
}
|
||||
|
||||
_isBoardActive = true;
|
||||
|
||||
if (PlayerController.Instance.Movement != null)
|
||||
{
|
||||
PlayerController.Instance.Movement.enabled = false;
|
||||
}
|
||||
|
||||
OctoIkArmsImproved arms = PlayerController.Instance.GetComponentInChildren<OctoIkArmsImproved>();
|
||||
if (arms != null)
|
||||
{
|
||||
arms.HideArms(3f);
|
||||
}
|
||||
|
||||
InputManager.SetContext(InputManager.InputContext.DetectiveBoard);
|
||||
|
||||
if (_cameraHeadBob != null)
|
||||
{
|
||||
_cameraHeadBob.SetMode(HeadBobMode.Disabled);
|
||||
}
|
||||
|
||||
if (CrosshairController.Instance != null)
|
||||
{
|
||||
CrosshairController.Instance.Hide();
|
||||
}
|
||||
|
||||
var cameraPan = PlayerController.Instance.CameraPanController;
|
||||
var originalSettings = cameraPan.Settings;
|
||||
|
||||
if (_playerAlignmentSettings != null)
|
||||
cameraPan.Settings = _playerAlignmentSettings;
|
||||
|
||||
cameraPan.SaveOriginalState();
|
||||
|
||||
cameraPan.AlignToTarget(DetectiveBoardCanvas.Instance.transform, () =>
|
||||
{
|
||||
DetectiveBoardVirtualCamera.Instance.ActivateFromPlayerPosition(
|
||||
PlayerController.Instance.PlayerCamera,
|
||||
DetectiveBoardCanvas.Instance.transform,
|
||||
DetectiveBoardCanvas.Instance.BoardRenderer
|
||||
);
|
||||
|
||||
// Show clue hand fan when board is ready
|
||||
if (ClueHandUI.Instance != null)
|
||||
ClueHandUI.Instance.SetHandVisible(true);
|
||||
|
||||
if (_playerAlignmentSettings != null)
|
||||
cameraPan.Settings = originalSettings;
|
||||
});
|
||||
}
|
||||
|
||||
private void HandleBoardInteraction()
|
||||
{
|
||||
var exitAction = InputManager.GetExitAction();
|
||||
if (exitAction != null && exitAction.WasPressedThisFrame())
|
||||
{
|
||||
DeactivateBoard();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeactivateBoard()
|
||||
{
|
||||
if (!_isBoardActive || DetectiveBoardVirtualCamera.Instance == null)
|
||||
return;
|
||||
|
||||
_isBoardActive = false;
|
||||
|
||||
// Hide clue hand fan
|
||||
if (ClueHandUI.Instance != null)
|
||||
ClueHandUI.Instance.SetHandVisible(false);
|
||||
|
||||
DetectiveBoardVirtualCamera.Instance.Deactivate(() =>
|
||||
{
|
||||
var cameraPan = PlayerController.Instance?.CameraPanController;
|
||||
if (cameraPan != null)
|
||||
{
|
||||
OctoIkArmsImproved arms = PlayerController.Instance.GetComponentInChildren<OctoIkArmsImproved>();
|
||||
if (arms != null)
|
||||
{
|
||||
arms.ShowArms(3f);
|
||||
}
|
||||
|
||||
cameraPan.ReturnToOriginalPosition(() =>
|
||||
{
|
||||
if (PlayerController.Instance?.Movement != null)
|
||||
{
|
||||
PlayerController.Instance.Movement.enabled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (PlayerController.Instance?.Movement != null)
|
||||
{
|
||||
PlayerController.Instance.Movement.enabled = true;
|
||||
}
|
||||
});
|
||||
|
||||
InputManager.SetContext(InputManager.InputContext.Normal);
|
||||
|
||||
RestoreHeadBob();
|
||||
|
||||
if (CrosshairController.Instance != null)
|
||||
{
|
||||
CrosshairController.Instance.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void RestoreHeadBob()
|
||||
{
|
||||
if (_cameraHeadBob == null)
|
||||
return;
|
||||
|
||||
_cameraHeadBob.ClearOverride();
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (DetectiveBoardCanvas.Instance == null)
|
||||
return;
|
||||
|
||||
Gizmos.color = _isBoardActive ? Color.green : Color.yellow;
|
||||
Gizmos.DrawWireSphere(DetectiveBoardCanvas.Instance.transform.position, _activationRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f9f72364623a2a4bb50f02537fd2e72
|
||||
@@ -0,0 +1,191 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Features.DetectiveBoard.Data;
|
||||
|
||||
namespace Unheimlich.Features.DetectiveBoard
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the detective board state and clue unlocking system.
|
||||
/// Tracks unlocked clues, connections, certainty levels, and eliminated hypotheses.
|
||||
/// Does NOT affect game progression - purely interpretive tool for the player.
|
||||
/// </summary>
|
||||
public class DetectiveBoardManager : Singleton<DetectiveBoardManager>
|
||||
{
|
||||
public enum CertaintyLevel
|
||||
{
|
||||
Uncertain,
|
||||
Possible,
|
||||
Confident,
|
||||
Certain
|
||||
}
|
||||
|
||||
public class ClueState
|
||||
{
|
||||
public ClueData Data;
|
||||
public bool IsUnlocked;
|
||||
public bool IsEliminated;
|
||||
}
|
||||
|
||||
public class Connection
|
||||
{
|
||||
public string FromClueID;
|
||||
public string ToClueID;
|
||||
public CertaintyLevel Certainty;
|
||||
public bool IsEliminated;
|
||||
}
|
||||
|
||||
[Header("References")]
|
||||
|
||||
private Dictionary<string, ClueState> _clueStates = new Dictionary<string, ClueState>();
|
||||
private List<Connection> _connections = new List<Connection>();
|
||||
|
||||
public IReadOnlyDictionary<string, ClueState> ClueStates => _clueStates;
|
||||
public IReadOnlyList<Connection> Connections => _connections;
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks a clue on the detective board. Can be triggered by any in-game event.
|
||||
/// </summary>
|
||||
public void UnlockClue(ClueData clueData)
|
||||
{
|
||||
if (clueData == null)
|
||||
{
|
||||
Debug.LogError("[DetectiveBoardManager] Attempted to unlock null clue!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_clueStates.ContainsKey(clueData.ClueID))
|
||||
{
|
||||
_clueStates[clueData.ClueID] = new ClueState
|
||||
{
|
||||
Data = clueData,
|
||||
IsUnlocked = true,
|
||||
IsEliminated = false
|
||||
};
|
||||
|
||||
OnClueUnlocked?.Invoke(clueData);
|
||||
}
|
||||
else if (!_clueStates[clueData.ClueID].IsUnlocked)
|
||||
{
|
||||
_clueStates[clueData.ClueID].IsUnlocked = true;
|
||||
OnClueUnlocked?.Invoke(clueData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all currently unlocked clues.
|
||||
/// Used by DetectiveBoardCanvas to display already-unlocked clues on initialization.
|
||||
/// </summary>
|
||||
public List<ClueData> GetUnlockedClues()
|
||||
{
|
||||
List<ClueData> unlockedClues = new List<ClueData>();
|
||||
foreach (var state in _clueStates.Values)
|
||||
{
|
||||
if (state.IsUnlocked)
|
||||
{
|
||||
unlockedClues.Add(state.Data);
|
||||
}
|
||||
}
|
||||
return unlockedClues;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks a clue by its ID string.
|
||||
/// </summary>
|
||||
public void UnlockClueByID(string clueID)
|
||||
{
|
||||
if (_clueStates.TryGetValue(clueID, out ClueState state))
|
||||
{
|
||||
if (!state.IsUnlocked)
|
||||
{
|
||||
state.IsUnlocked = true;
|
||||
OnClueUnlocked?.Invoke(state.Data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[DetectiveBoardManager] Clue ID '{clueID}' not found!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a clue in the system without unlocking it.
|
||||
/// </summary>
|
||||
public void RegisterClue(ClueData clueData)
|
||||
{
|
||||
if (clueData == null || _clueStates.ContainsKey(clueData.ClueID))
|
||||
return;
|
||||
|
||||
_clueStates[clueData.ClueID] = new ClueState
|
||||
{
|
||||
Data = clueData,
|
||||
IsUnlocked = false,
|
||||
IsEliminated = false
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a connection between two clues.
|
||||
/// </summary>
|
||||
public void CreateConnection(string fromClueID, string toClueID, CertaintyLevel certainty = CertaintyLevel.Uncertain)
|
||||
{
|
||||
if (!_clueStates.ContainsKey(fromClueID) || !_clueStates.ContainsKey(toClueID))
|
||||
{
|
||||
Debug.LogWarning($"[DetectiveBoardManager] Cannot create connection - one or both clues not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
Connection existing = _connections.Find(c =>
|
||||
(c.FromClueID == fromClueID && c.ToClueID == toClueID) ||
|
||||
(c.FromClueID == toClueID && c.ToClueID == fromClueID));
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
existing.Certainty = certainty;
|
||||
}
|
||||
else
|
||||
{
|
||||
_connections.Add(new Connection
|
||||
{
|
||||
FromClueID = fromClueID,
|
||||
ToClueID = toClueID,
|
||||
Certainty = certainty,
|
||||
IsEliminated = false
|
||||
});
|
||||
|
||||
OnConnectionCreated?.Invoke(fromClueID, toClueID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a clue as eliminated (incorrect hypothesis).
|
||||
/// </summary>
|
||||
public void EliminateClue(string clueID)
|
||||
{
|
||||
if (_clueStates.TryGetValue(clueID, out ClueState state))
|
||||
{
|
||||
state.IsEliminated = true;
|
||||
OnClueEliminated?.Invoke(clueID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a connection as eliminated.
|
||||
/// </summary>
|
||||
public void EliminateConnection(string fromClueID, string toClueID)
|
||||
{
|
||||
Connection connection = _connections.Find(c =>
|
||||
(c.FromClueID == fromClueID && c.ToClueID == toClueID) ||
|
||||
(c.FromClueID == toClueID && c.ToClueID == fromClueID));
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
connection.IsEliminated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public event System.Action<ClueData> OnClueUnlocked;
|
||||
public event System.Action<string, string> OnConnectionCreated;
|
||||
public event System.Action<string> OnClueEliminated;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b187cdccaa498441a752e8f49ff4290
|
||||
Reference in New Issue
Block a user