first
This commit is contained in:
49
Assets/02_Scripts/_UI/Communication/DialogHud.cs
Normal file
49
Assets/02_Scripts/_UI/Communication/DialogHud.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
// 화면 하단 등에 고정된 스크린 스페이스 대사 HUD 싱글턴.
|
||||
// DialogPlayer가 대사 노드를 재생할 때 Show()로 화자 이름 + 대사를 표시한다.
|
||||
public class DialogHud : MonoBehaviour
|
||||
{
|
||||
public static DialogHud Instance { get; private set; }
|
||||
|
||||
[Header("Refs")]
|
||||
[SerializeField] private GameObject _panel; // 대사 패널(토글 대상). 보통 이 오브젝트의 자식.
|
||||
[SerializeField] private TMP_Text _speakerName;
|
||||
[SerializeField] private TMP_Text _dialogueText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this) { Destroy(gameObject); return; }
|
||||
Instance = this;
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
// 화자 이름 + 대사 표시.
|
||||
// - speakerNameOverride가 비어있지 않으면 CharacterData.Name 대신 그 이름을 표시한다 (예: "???")
|
||||
public void Show(CharacterData speaker, string text, string speakerNameOverride = null)
|
||||
{
|
||||
if (_speakerName != null)
|
||||
{
|
||||
string speakerName = !string.IsNullOrEmpty(speakerNameOverride) ? speakerNameOverride
|
||||
: speaker != null ? speaker.Name : string.Empty;
|
||||
_speakerName.text = DialogVariables.Format(speakerName); // {key} 토큰 치환
|
||||
}
|
||||
if (_dialogueText != null)
|
||||
_dialogueText.text = DialogVariables.Format(text); // {key} 토큰 치환
|
||||
|
||||
if (_panel != null) _panel.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (_dialogueText != null) _dialogueText.text = string.Empty;
|
||||
if (_speakerName != null) _speakerName.text = string.Empty;
|
||||
if (_panel != null) _panel.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user