Add utils + refacto

This commit is contained in:
2026-01-30 17:39:26 +01:00
parent 9ff17b5305
commit 23d3cb5d2c
29 changed files with 675 additions and 461 deletions
@@ -1,11 +1,12 @@
using UnityEngine;
using TMPro;
using Unheimlich.Core;
using Unheimlich.Utility;
namespace Unheimlich.UI
{
public class DialogueScreenUI : MonoBehaviour
public class DialogueScreenUI : Singleton<DialogueScreenUI>
{
public static DialogueScreenUI Instance { get; private set; }
[Header("UI References")]
[SerializeField] private GameObject _dialoguePanel;
@@ -17,16 +18,8 @@ namespace Unheimlich.UI
private CanvasGroup _canvasGroup;
private void Awake()
protected override void OnAwake()
{
if (Instance != null && Instance != this)
{
Debug.LogWarning("[DialogueScreenUI] Multiple instances detected! Destroying duplicate.");
Destroy(gameObject);
return;
}
Instance = this;
if (_dialoguePanel != null)
{
@@ -37,12 +30,6 @@ namespace Unheimlich.UI
}
}
private void OnDestroy()
{
if (Instance == this)
Instance = null;
}
public void Show(string speaker, string dialogue)
{
if (_speakerText != null)
@@ -73,18 +60,19 @@ namespace Unheimlich.UI
{
if (_canvasGroup != null && _dialoguePanel != null)
{
LeanTween.cancel(_dialoguePanel);
LeanTween.alphaCanvas(_canvasGroup, 0f, _fadeOutDuration)
.setOnComplete(() =>
{
TweenHelper.FadeCanvasGroup(
_canvasGroup,
0f,
_fadeOutDuration,
() => {
Hide();
onComplete?.Invoke();
onComplete.SafeInvoke();
});
}
else
{
Hide();
onComplete?.Invoke();
onComplete.SafeInvoke();
}
}
}