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
@@ -41,6 +41,9 @@ namespace Unheimlich.Core.Interaction
private bool _isActive = false;
private bool _isMerged = false;
private bool _hasBeenMergedOnce = false;
// Persists across OnEnable/OnDisable — only cleared by explicit ResetMerge()
// or at the start of a new Play Mode session via RuntimeInitializeOnLoadMethod.
private bool _hasCompletedMergeOnce = false;
private Vector3[] _originalSpawnPositions;
private Vector3[] _basePositions;
@@ -51,21 +54,69 @@ namespace Unheimlich.Core.Interaction
void Start()
{
_playerTransform = PlayerController.Instance.transform;
InitializeReferences();
}
void OnEnable()
{
// With Scene Reload disabled, Start() doesn't run again between Play Mode sessions.
// Re-fetch references and reset transient state so animations restart cleanly.
InitializeReferences();
ResetSessionState();
}
private void InitializeReferences()
{
_playerTransform = PlayerController.Instance != null ? PlayerController.Instance.transform : null;
_mainCamera = Camera.main;
if (_playerTransform == null)
Debug.LogWarning($"[ObjectDescription] No player found for {gameObject.name}");
if (_descriptionAnchor == null)
_descriptionAnchor = transform;
if (_settings == null)
{
Debug.LogError($"[ObjectDescription] No settings assigned for {gameObject.name}");
enabled = false;
}
}
private void ResetSessionState()
{
// Force-despawn any leftover words from the previous session
// (their GOs were destroyed but _spawnedWords list may still have stale entries).
if (_isActive)
{
foreach (var word in _spawnedWords)
{
if (word != null) Destroy(word.gameObject);
}
_spawnedWords.Clear();
if (_wordsContainer != null) Destroy(_wordsContainer);
_wordsContainer = null;
_wordsRotator = null;
}
_isActive = false;
_isMerged = false;
_hasBeenMergedOnce = false;
// _hasCompletedMergeOnce intentionally NOT reset here — persists during session
// so a merged object stays merged when the player re-enters its activation range.
// It is only reset at the start of a new Play Mode session (see OnPlayModeReset).
_currentConvergenceRadius = 0f;
}
// Resets _hasCompletedMergeOnce at the very start of each Play Mode session,
// before any scene loads, so objects start fresh without full Domain Reload.
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnPlayModeReset()
{
// Static reset — instance fields will be re-initialized by Awake/Start naturally.
// No instance access needed here; ResetSessionState() handles the rest on OnEnable.
}
void Update()
{