chore: Project Restructuring & Theatre
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Core.Utils;
|
||||
|
||||
namespace Unheimlich.Features.Dialogue.UI
|
||||
{
|
||||
public class DialogueScreenUI : Singleton<DialogueScreenUI>
|
||||
{
|
||||
|
||||
[Header("UI References")]
|
||||
[SerializeField] private GameObject _dialoguePanel;
|
||||
[SerializeField] private TextMeshProUGUI _speakerText;
|
||||
[SerializeField] private TextMeshProUGUI _dialogueText;
|
||||
|
||||
[Header("Fade Settings")]
|
||||
[SerializeField] private float _fadeOutDuration = 0.5f;
|
||||
|
||||
private CanvasGroup _canvasGroup;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
|
||||
if (_dialoguePanel != null)
|
||||
{
|
||||
_canvasGroup = _dialoguePanel.GetComponent<CanvasGroup>();
|
||||
|
||||
if (_canvasGroup == null)
|
||||
_canvasGroup = _dialoguePanel.AddComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(string speaker, string dialogue)
|
||||
{
|
||||
if (_speakerText != null)
|
||||
_speakerText.text = speaker;
|
||||
|
||||
if (_dialogueText != null)
|
||||
_dialogueText.text = dialogue;
|
||||
|
||||
if (_dialoguePanel != null)
|
||||
{
|
||||
_dialoguePanel.SetActive(true);
|
||||
|
||||
if (_canvasGroup != null)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
_canvasGroup.alpha = 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (_dialoguePanel != null)
|
||||
_dialoguePanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void FadeOutAndHide(System.Action onComplete = null)
|
||||
{
|
||||
if (_canvasGroup != null && _dialoguePanel != null)
|
||||
{
|
||||
TweenHelper.FadeCanvasGroup(
|
||||
_canvasGroup,
|
||||
0f,
|
||||
_fadeOutDuration,
|
||||
() => {
|
||||
Hide();
|
||||
onComplete.SafeInvoke();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
onComplete.SafeInvoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user