대화 프로토타입
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
// 화자 몸통 앞에 떠 있는 World-space 선택지 UI 싱글턴
|
||||
// DialogPlayer가 Show()를 await해서 선택된 인덱스를 받아감
|
||||
// World-space 선택지 UI 싱글턴.
|
||||
// DialogPlayer가 Show()를 await해서 선택된 인덱스를 받아감.
|
||||
// 배치(Placement)는 DialogHud가 담당하므로, 이 오브젝트를 DialogHud의 자식으로 두면 함께 따라온다.
|
||||
public class ChoiceHud : MonoBehaviour
|
||||
{
|
||||
public static ChoiceHud Instance { get; private set; }
|
||||
@@ -14,11 +15,6 @@ public class ChoiceHud : MonoBehaviour
|
||||
[SerializeField] private DialogChoiceRow _rowPrefab;
|
||||
[SerializeField] private TMP_Text ChoiceQuestion;
|
||||
|
||||
[Header("Placement")]
|
||||
[SerializeField] private float _chestHeight = 1.2f; // 화자 발 기준 가슴 높이
|
||||
[SerializeField] private float _forwardOffset = 0.5f; // 화자→플레이어 방향으로 띄울 거리
|
||||
|
||||
private Transform _speakerTransform;
|
||||
private readonly List<DialogChoiceRow> _rows = new();
|
||||
private AwaitableCompletionSource<int> _completion;
|
||||
|
||||
@@ -42,13 +38,11 @@ private void OnDisable()
|
||||
_completion = null;
|
||||
}
|
||||
|
||||
public async Awaitable<int> Show(CharacterData speaker,string choiceQuestion, List<DialogChoice> choices)
|
||||
public async Awaitable<int> Show(string choiceQuestion, List<DialogChoice> choices)
|
||||
{
|
||||
if (choices == null || choices.Count == 0) return 0;
|
||||
|
||||
_speakerTransform = speaker != null ? CharacterVoiceObject.Find(speaker)?.transform : null;
|
||||
|
||||
ChoiceQuestion.text = choiceQuestion;
|
||||
SetQuestion(choiceQuestion);
|
||||
ClearRows();
|
||||
for (int i = 0; i < choices.Count; i++)
|
||||
{
|
||||
@@ -81,10 +75,19 @@ private void HandleClicked(int index)
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
ChoiceQuestion.text = "";
|
||||
SetQuestion(null);
|
||||
ClearRows();
|
||||
if (_root != null) _root.SetActive(false);
|
||||
_speakerTransform = null;
|
||||
}
|
||||
|
||||
// 질문이 비어 있으면 질문 텍스트 자체를 숨긴다. (기본값: 질문 없음 → 안 보임)
|
||||
// 질문은 보통 노드의 대사(TalkText)로 대신하므로 ChoiceQuestion은 비워둬도 된다.
|
||||
private void SetQuestion(string question)
|
||||
{
|
||||
if (ChoiceQuestion == null) return;
|
||||
bool hasQuestion = !string.IsNullOrWhiteSpace(question);
|
||||
ChoiceQuestion.text = hasQuestion ? question : string.Empty;
|
||||
ChoiceQuestion.gameObject.SetActive(hasQuestion);
|
||||
}
|
||||
|
||||
private void ClearRows()
|
||||
@@ -97,24 +100,4 @@ private void ClearRows()
|
||||
}
|
||||
_rows.Clear();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_root == null || !_root.activeSelf) return;
|
||||
if (_speakerTransform == null || Camera.main == null) return;
|
||||
|
||||
var camTr = Camera.main.transform;
|
||||
|
||||
// 화자에서 플레이어 카메라로 향하는 수평 방향 (yaw만)
|
||||
Vector3 toCam = camTr.position - _speakerTransform.position;
|
||||
toCam.y = 0f;
|
||||
if (toCam.sqrMagnitude < 0.0001f) return;
|
||||
Vector3 dir = toCam.normalized;
|
||||
|
||||
Vector3 chestWorld = _speakerTransform.position + Vector3.up * _chestHeight;
|
||||
_root.transform.position = chestWorld + dir * _forwardOffset;
|
||||
|
||||
// 빌보드 — 캔버스의 -Z(읽는 면)가 카메라를 향하도록 +Z를 카메라 반대로
|
||||
_root.transform.rotation = Quaternion.LookRotation(-dir);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user