Add Screen display mode with dedicated UI component
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace Unheimlich.UI
|
||||
{
|
||||
public class DialogueScreenUI : MonoBehaviour
|
||||
{
|
||||
public static DialogueScreenUI Instance { get; private set; }
|
||||
|
||||
[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;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Debug.LogWarning("[DialogueScreenUI] Multiple instances detected! Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
if (_dialoguePanel != null)
|
||||
{
|
||||
_canvasGroup = _dialoguePanel.GetComponent<CanvasGroup>();
|
||||
|
||||
if (_canvasGroup == null)
|
||||
_canvasGroup = _dialoguePanel.AddComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Instance == this)
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
LeanTween.alphaCanvas(_canvasGroup, 0f, _fadeOutDuration)
|
||||
.setOnComplete(() =>
|
||||
{
|
||||
Hide();
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc4c44e24ba19844b822608a46bde428
|
||||
@@ -1,11 +1,9 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unheimlich.Data.Dialogues;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
using Unheimlich.Interactions.FloatingWords;
|
||||
using Unheimlich.Interactions.Dialogues;
|
||||
|
||||
namespace Unheimlich.UI
|
||||
{
|
||||
@@ -15,11 +13,11 @@ namespace Unheimlich.UI
|
||||
/// </summary>
|
||||
public class DialogueUI : MonoBehaviour
|
||||
{
|
||||
[Header("Panels")]
|
||||
[Header("Panels - World Mode")]
|
||||
[SerializeField] private GameObject _dialoguePanel;
|
||||
public GameObject ChoiceContainer;
|
||||
|
||||
[Header("Text Fields")]
|
||||
[Header("Text Fields - World Mode")]
|
||||
[SerializeField] private TextMeshProUGUI _speakerText;
|
||||
[SerializeField] private TextMeshProUGUI _contentText;
|
||||
|
||||
@@ -43,6 +41,8 @@ namespace Unheimlich.UI
|
||||
private float _sortTimer = 0f;
|
||||
private const float SORT_INTERVAL = 0.1f;
|
||||
|
||||
private DialogueDisplayMode _currentDisplayMode = DialogueDisplayMode.World;
|
||||
|
||||
private static readonly Vector3 ViewportCenter = new Vector3(0.5f, 0.5f, 0f);
|
||||
|
||||
private void Awake()
|
||||
@@ -76,42 +76,85 @@ namespace Unheimlich.UI
|
||||
SortChoicesByDistance();
|
||||
}
|
||||
|
||||
public void ShowDialogueBox(string speaker, string content)
|
||||
public void ShowDialogueBox(string speaker, string content, DialogueDisplayMode displayMode = DialogueDisplayMode.World)
|
||||
{
|
||||
_speakerText.text = speaker;
|
||||
_contentText.text = content;
|
||||
_dialoguePanel.SetActive(true);
|
||||
_currentDisplayMode = displayMode;
|
||||
|
||||
if (_dialogueCanvasGroup != null)
|
||||
if (displayMode == DialogueDisplayMode.World)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
_dialogueCanvasGroup.alpha = 1f;
|
||||
if (DialogueScreenUI.Instance != null)
|
||||
DialogueScreenUI.Instance.Hide();
|
||||
|
||||
_speakerText.text = speaker;
|
||||
_contentText.text = content;
|
||||
_dialoguePanel.SetActive(true);
|
||||
|
||||
if (_dialogueCanvasGroup != null)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
_dialogueCanvasGroup.alpha = 1f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_dialoguePanel != null)
|
||||
_dialoguePanel.SetActive(false);
|
||||
|
||||
if (DialogueScreenUI.Instance != null)
|
||||
DialogueScreenUI.Instance.Show(speaker, content);
|
||||
else
|
||||
Debug.LogWarning("[DialogueUI] DialogueScreenUI.Instance is null! Make sure DialogueScreenUI component exists in the scene.");
|
||||
}
|
||||
}
|
||||
|
||||
public void HideDialogueBox()
|
||||
{
|
||||
_dialoguePanel.SetActive(false);
|
||||
if (_dialoguePanel != null)
|
||||
_dialoguePanel.SetActive(false);
|
||||
|
||||
if (DialogueScreenUI.Instance != null)
|
||||
DialogueScreenUI.Instance.Hide();
|
||||
|
||||
ChoiceContainer.SetActive(false);
|
||||
HideChoices();
|
||||
}
|
||||
|
||||
public void FadeOutAndHide(System.Action onComplete = null)
|
||||
{
|
||||
if (_dialogueCanvasGroup != null)
|
||||
if (_currentDisplayMode == DialogueDisplayMode.World)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
LeanTween.alphaCanvas(_dialogueCanvasGroup, 0f, _fadeOutDuration)
|
||||
.setOnComplete(() =>
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
if (_dialogueCanvasGroup != null && _dialoguePanel != null)
|
||||
{
|
||||
LeanTween.cancel(_dialoguePanel);
|
||||
LeanTween.alphaCanvas(_dialogueCanvasGroup, 0f, _fadeOutDuration)
|
||||
.setOnComplete(() =>
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
if (DialogueScreenUI.Instance != null)
|
||||
{
|
||||
DialogueScreenUI.Instance.FadeOutAndHide(() =>
|
||||
{
|
||||
HideChoices();
|
||||
ChoiceContainer.SetActive(false);
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
HideDialogueBox();
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user