This commit is contained in:
2026-07-26 18:47:19 +09:00
parent 53bad30836
commit 880732dd33
16 changed files with 247 additions and 37 deletions

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 489593e55eab6a8489fae884d1d22ad2
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -68,10 +68,10 @@ public async Awaitable Play()
// 다른 NPC가 실제 대사를 재생 중이면 무시 — 대화 중 다른 NPC 상호작용 차단
if (_entryInProgress != null) return;
// 다른 NPC의 선택 메뉴가 떠 있으면 먼저 취소한다.
// 다른 NPC의 대화 선택 메뉴가 떠 있으면 먼저 취소한다.
// (취소된 쪽의 Play가 이 자리에서 HUD 숨김 등 정리를 마친 뒤에 이쪽이 시작된다)
if (ChoiceHud.Instance != null)
ChoiceHud.Instance.CancelPending();
if (DialogEnterHud.Instance != null)
DialogEnterHud.Instance.CancelPending();
// 선택 메뉴가 떠 있는 동안에도 재진입을 막아야 하므로 여기서 잠근다.
IsPlaying = true;
@@ -116,9 +116,9 @@ private async Awaitable PlayGroupForced(DialogGroup group)
if (group == null || IsPlaying) return;
if (_entryInProgress != null) return; // 다른 NPC가 대사 재생 중
// 다른 NPC의 선택 메뉴가 떠 있으면 먼저 취소
if (ChoiceHud.Instance != null)
ChoiceHud.Instance.CancelPending();
// 다른 NPC의 대화 선택 메뉴가 떠 있으면 먼저 취소
if (DialogEnterHud.Instance != null)
DialogEnterHud.Instance.CancelPending();
IsPlaying = true;
PushActive();
@@ -156,10 +156,10 @@ private List<StoryBeat> FindPlayableBeats()
return lm.Database.GetPlayableBeats(lm.Current, _voice.Character);
}
// 재생 가능한 대화가 여럿일 때 ChoiceHud로 플레이어에게 고르게 한다. 취소되면 null.
// 재생 가능한 대화가 여럿일 때 DialogEnterHud로 플레이어에게 고르게 한다. 취소되면 null.
private async Awaitable<StoryBeat> SelectBeat(List<StoryBeat> playable)
{
if (ChoiceHud.Instance == null)
if (DialogEnterHud.Instance == null)
return playable[0]; // 선택 UI가 없으면 기존처럼 최상단 우선
var options = new List<DialogChoice>(playable.Count);
@@ -173,12 +173,12 @@ private async Awaitable<StoryBeat> SelectBeat(List<StoryBeat> playable)
try
{
int picked = await ChoiceHud.Instance.Show(null, options);
int picked = await DialogEnterHud.Instance.Show(options);
return playable[picked];
}
catch (OperationCanceledException)
{
// 대기 중 ChoiceHud가 비활성화됨(씬 전환 등) — 재생하지 않음
// 대기 중 DialogEnterHud가 비활성화됨(씬 전환 등) — 재생하지 않음
return null;
}
}

View File

@@ -0,0 +1,128 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
// "어떤 대화를 걸지" 고르는 메뉴 (역전재판식 "대화하기" — 후보가 여럿이면 골라서 시작).
// DialogEnterUI.uxml의 ListView로 후보를 띄우고, 행을 클릭하면 그 인덱스를 반환한다.
// 대사 도중의 분기 선택지(ChoiceHud)와는 별개다 — 이건 대화를 시작하기 전 단계의 UI.
// DialogPlayer.SelectBeat가 재생 가능한 비트가 여럿일 때 사용한다.
[RequireComponent(typeof(UIDocument))]
public class DialogEnterHud : MonoBehaviour
{
public static DialogEnterHud Instance { get; private set; }
private UIDocument _document;
private VisualElement _root; // 전체 토글 대상(#Body)
private ListView _listView;
private bool _ready;
private List<DialogChoice> _options;
private AwaitableCompletionSource<int> _completion;
private void Awake()
{
if (Instance != null && Instance != this) { Destroy(gameObject); return; }
Instance = this;
_document = GetComponent<UIDocument>();
}
private void Start() => Hide();
private void OnDestroy()
{
if (Instance == this) Instance = null;
}
private void OnDisable()
{
// 씬 전환 등으로 비활성화될 때 진행 중 대기 정리
_completion?.TrySetCanceled();
_completion = null;
}
// rootVisualElement가 준비된 뒤 한 번만 요소를 캐싱하고 ListView 콜백을 건다.
private bool EnsureRefs()
{
if (_ready) return true;
var root = _document != null ? _document.rootVisualElement : null;
if (root == null) return false;
_root = root.Q<VisualElement>("Body");
_listView = root.Q<ListView>();
if (_listView != null)
{
_listView.selectionType = SelectionType.Single;
_listView.fixedItemHeight = 40; // 행 높이 (필요하면 인스펙터의 Fixed Item Height로 조정)
_listView.bindItem = BindRow; // item-template(DialogEnterRow)이 makeItem을 담당, 바인딩만 우리가
_listView.selectionChanged += OnSelectionChanged;
}
_ready = true;
return true;
}
// 대기 중인 선택을 취소하고 메뉴를 닫는다 (다른 NPC와 대화를 새로 시작할 때 등).
// 취소된 쪽의 await Show(...)는 OperationCanceledException으로 빠져나간다.
public void CancelPending() => _completion?.TrySetCanceled();
// 후보 목록을 띄우고 고른 인덱스를 반환한다. 취소되면 OperationCanceledException.
public async Awaitable<int> Show(List<DialogChoice> options)
{
if (options == null || options.Count == 0) return 0;
if (!EnsureRefs()) return 0;
// 이전 호출이 아직 대기 중이면 먼저 취소한다 (마지막 호출이 이긴다).
CancelPending();
_options = options;
_listView.itemsSource = options;
_listView.ClearSelection();
_listView.Rebuild();
_root.style.display = DisplayStyle.Flex;
var completion = new AwaitableCompletionSource<int>();
_completion = completion;
int result;
try
{
result = await completion.Awaitable;
}
finally
{
// 내가 아직 현재 세션일 때만 정리 — 취소 직후 다른 NPC가 새로 띄운 메뉴를 지우면 안 된다
if (_completion == completion)
{
_completion = null;
Hide();
}
}
return result;
}
// ListView 행(item-template = DialogEnterRow.uxml)에 후보 이름을 채운다.
// 행 템플릿의 Label엔 name이 없어 타입으로 찾는다.
private void BindRow(VisualElement element, int i)
{
var label = element.Q<Label>();
if (label != null && _options != null && i < _options.Count)
label.text = DialogVariables.Format(_options[i].ChoiceText); // {key} 토큰 치환
}
// 행을 클릭(선택)하면 그 인덱스로 결과를 확정한다
private void OnSelectionChanged(IEnumerable<object> _)
{
if (_completion == null) return;
int idx = _listView.selectedIndex;
if (idx < 0) return;
_completion.TrySetResult(idx);
}
private void Hide()
{
if (!EnsureRefs()) return;
_listView.itemsSource = null;
_listView.Rebuild();
_root.style.display = DisplayStyle.None;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9d1bcb66b4b42374199694adef29e91a

View File

@@ -1,49 +1,69 @@
using TMPro;
using UnityEngine;
using UnityEngine.UIElements;
// 화면 하단 등에 고정된 스크린 스페이스 대사 HUD 싱글턴.
// DialogPlayer가 대사 노드를 재생할 때 Show()로 화자 이름 + 대사를 표시한다.
// UI Toolkit 버전 대사 HUD. DialogUI.uxml의 요소(#SpeakerName / #DialogText / #DialogField)를 잡아
// 화자 이름 + 대사를 표시한다.
// 공개 API(Instance / Show / Hide)는 기존 uGUI 버전과 동일 — DialogPlayer는 수정 없이 그대로 쓴다.
[RequireComponent(typeof(UIDocument))]
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 UIDocument _document;
private VisualElement _panel; // 대사 패널(#DialogField) — 토글 대상
private Label _speakerName;
private Label _dialogText;
private bool _ready;
private void Awake()
{
if (Instance != null && Instance != this) { Destroy(gameObject); return; }
Instance = this;
Hide();
_document = GetComponent<UIDocument>();
}
// 시작 시 숨김 (이 시점엔 UIDocument의 visual tree가 준비돼 있다)
private void Start() => Hide();
private void OnDestroy()
{
if (Instance == this) Instance = null;
}
// rootVisualElement가 준비된 뒤 한 번만 요소를 캐싱한다.
// (스크립트 실행 순서상 UIDocument보다 먼저 OnEnable이 돌 수 있어 지연 초기화로 안전하게 처리)
private bool EnsureRefs()
{
if (_ready) return true;
var root = _document != null ? _document.rootVisualElement : null;
if (root == null) return false;
_panel = root.Q<VisualElement>("DialogField");
_speakerName = root.Q<Label>("SpeakerName");
_dialogText = root.Q<Label>("DialogText");
_ready = true;
return true;
}
// 화자 이름 + 대사 표시.
// - 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 (!EnsureRefs()) return;
if (_panel != null) _panel.SetActive(true);
string speakerName = !string.IsNullOrEmpty(speakerNameOverride) ? speakerNameOverride
: speaker != null ? speaker.Name : string.Empty;
if (_speakerName != null) _speakerName.text = DialogVariables.Format(speakerName); // {key} 토큰 치환
if (_dialogText != null) _dialogText.text = DialogVariables.Format(text);
if (_panel != null) _panel.style.display = DisplayStyle.Flex;
}
public void Hide()
{
if (_dialogueText != null) _dialogueText.text = string.Empty;
if (!EnsureRefs()) return;
if (_speakerName != null) _speakerName.text = string.Empty;
if (_panel != null) _panel.SetActive(false);
if (_dialogText != null) _dialogText.text = string.Empty;
if (_panel != null) _panel.style.display = DisplayStyle.None;
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 09fe35be3b1c20b4488aa2307c9849f6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:VisualElement name="Body" style="flex-grow: 1; align-items: center; justify-content: center;">
<ui:VisualElement name="Row" style="flex-grow: 0; width: 360px; height: 30px; flex-shrink: 0; background-color: rgb(255, 252, 220); justify-content: center; align-items: center;">
<ui:Label text="Label" style="color: rgb(255, 85, 94); -unity-font-style: bold;"/>
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2e6fe492031ca054a9d695b6ba0120a9
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -1,8 +1,8 @@
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:VisualElement name="Body" style="flex-grow: 1;">
<ui:VisualElement name="Body" style="flex-grow: 1; width: 1920px; height: 1080px;">
<ui:VisualElement name="Overlay" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0.502); justify-content: center; align-items: center;">
<ui:VisualElement name="DialogList" style="flex-grow: 0; width: 50%; height: 70%; align-self: center; align-content: flex-start; justify-content: center; margin-bottom: 0; flex-shrink: 0; translate: 0 -50px; align-items: center;">
<ui:ListView style="flex-shrink: 0; width: 800px; height: 600px;"/>
<ui:ListView item-template="project://database/Assets/08_UI/DialogEnterRow.uxml?fileID=9197481963319205126&amp;guid=2e6fe492031ca054a9d695b6ba0120a9&amp;type=3#DialogEnterRow" style="flex-shrink: 0; width: 800px; height: 600px;"/>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a671407c1b53084388efb1b64d98ea0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,9 @@
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/GlobalStyle.uss?fileID=7433441132597879392&amp;guid=daee454451ae094468e43c05937249f6&amp;type=3#GlobalStyle"/>
<ui:VisualElement name="Body" style="flex-grow: 1; flex-direction: column-reverse;">
<ui:VisualElement name="DialogField" style="flex-grow: 0; width: auto; height: 450px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; background-color: rgba(0, 0, 0, 0.624); justify-content: flex-start; align-content: flex-start; flex-direction: column;">
<ui:Label text="Label" name="SpeakerName" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 10px; padding-right: 20px; padding-bottom: 10px; padding-left: 20px; height: 100px; width: 400px; -unity-text-align: middle-center;"/>
<Style src="project://database/Assets/08_UI/GlobalStyle.uss?fileID=7433441132597879392&amp;guid=daee454451ae094468e43c05937249f6&amp;type=3#GlobalStyle"/>
<ui:VisualElement name="Body" style="flex-grow: 1; flex-direction: column; justify-content: flex-end; flex-shrink: 1; width: 1920px; height: 1080px; align-content: auto; align-self: auto;">
<ui:VisualElement name="DumyBox" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); height: auto; flex-shrink: 1;"/>
<ui:VisualElement name="DialogField" style="flex-grow: 0; width: auto; height: 480px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; background-color: rgba(0, 0, 0, 0.624); justify-content: flex-start; align-content: flex-start; flex-direction: column; flex-shrink: 0;">
<ui:Label text="nnn" name="SpeakerName" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 10px; padding-right: 20px; padding-bottom: 10px; padding-left: 20px; height: 100px; width: 400px; -unity-text-align: middle-center;"/>
<ui:Label text="Label" name="DialogText" style="text-overflow: ellipsis; flex-shrink: 1; flex-grow: 1; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px;"/>
</ui:VisualElement>
</ui:VisualElement>

View File

@@ -0,0 +1 @@
VisualElement {}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b85de089b6fba12468baf434036c38d5
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
unsupportedSelectorAction: 0