Add Screen display mode with dedicated UI component

This commit is contained in:
2026-01-27 16:46:46 +01:00
parent 203b00578a
commit d1b7104676
37 changed files with 1306 additions and 254 deletions
+65 -22
View File
@@ -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();
}
}
}