Fix: cleanup and minor perf improvements

This commit is contained in:
Ferlat Thibaud
2026-03-25 01:28:18 +01:00
parent 9fd251f6e9
commit e69bdb93f8
21 changed files with 130 additions and 136 deletions
@@ -63,7 +63,7 @@ namespace Unheimlich.Features.Dialogue
/// </summary>
public void Update()
{
if (!_manager.IsInDialogue || !_manager.CurrentDialogueUI.AreChoicesVisible())
if (!_manager.IsDialogueActive || !_manager.CurrentDialogueUI.AreChoicesVisible())
return;
_raycastTimer += Time.deltaTime;
@@ -16,7 +16,7 @@ namespace Unheimlich.Features.Dialogue
{
[Header("State")]
public bool IsInDialogue = false;
[SerializeField] private bool IsInDialogue = false;
[Header("Focus Settings")]
[SerializeField] private LayerMask _choiceLayer;
@@ -65,19 +65,7 @@ namespace Unheimlich.Features.Dialogue
if (_focusSystem != null)
{
_mainCamera = Camera.main;
_focusSystem = new DialogueFocusSystem(
this,
_mainCamera,
PlayerController.Instance?.CameraEffects,
_choiceLayer,
_focusRange,
_focusTime,
_raycastInterval,
_recoveryDuration,
_focusRetentionTime,
_fallbackShakeIntensity
);
_focusSystem.OnChoiceMade += (choice) => OnChoiceMade?.Invoke(choice);
InitFocusSystem();
// Also reset dialogue state in case we exited mid-dialogue
IsInDialogue = false;
@@ -89,7 +77,15 @@ namespace Unheimlich.Features.Dialogue
private void Start()
{
_mainCamera = Camera.main;
InitFocusSystem();
}
/// <summary>
/// Creates or recreates the DialogueFocusSystem with the current inspector settings.
/// Called from Start and OnEnabled (domain-reload-less re-entry).
/// </summary>
private void InitFocusSystem()
{
_focusSystem = new DialogueFocusSystem(
this,
_mainCamera,
@@ -10,14 +10,16 @@ namespace Unheimlich.Features.Dialogue.UI
{
private Transform _cameraTransform;
private void Start()
private void Awake()
{
_cameraTransform = Camera.main.transform;
_cameraTransform = Camera.main != null ? Camera.main.transform : null;
if (_cameraTransform == null)
Debug.LogWarning($"BillboardUI on {gameObject.name}: Main camera not found!");
}
private void Start() { }
private void LateUpdate()
{
if (_cameraTransform != null)
@@ -48,11 +48,14 @@ namespace Unheimlich.Features.Dialogue.UI
private int _fadeCanvasTweenId = -1;
private int _rotationTweenId = -1;
private List<int> _floatingTweenIds = new List<int>();
private Camera _mainCamera;
private static readonly Vector3 ViewportCenter = new Vector3(0.5f, 0.5f, 0f);
private void Awake()
{
_mainCamera = Camera.main;
if (_dialogueCanvasGroup == null && _dialoguePanel != null)
{
_dialogueCanvasGroup = _dialoguePanel.GetComponent<CanvasGroup>();
@@ -366,7 +369,7 @@ namespace Unheimlich.Features.Dialogue.UI
_sortTimer = 0f;
FloatingWordsSpawner.SortByDistance(_activeChoices, Camera.main);
FloatingWordsSpawner.SortByDistance(_activeChoices, _mainCamera);
}
}
}