Add utils + refacto
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user