2026-06-19 월드다이얼로그 프로토타입
This commit is contained in:
@@ -6,6 +6,12 @@
|
||||
public class DialogPlayer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<DialogGroup> _dialogGroups;
|
||||
|
||||
[Header("Dialog HUD Placement")] // 씬에서 캐릭터 위치/주변(벽 등)에 맞춰 조절
|
||||
[SerializeField] private float _hudChestHeight = 1.2f; // 화자 발 기준 가슴 높이
|
||||
[SerializeField] private float _hudForwardOffset = 0.5f; // 화자→플레이어 방향으로 띄울 거리
|
||||
[SerializeField] private float _hudLateralOffset = 0f; // 좌우 오프셋 (+ 플레이어 시점 오른쪽)
|
||||
|
||||
private Dictionary<string, DialogGroup> _dialogGroupMap;
|
||||
private Animator _animator;
|
||||
private int _initialGestureHash;
|
||||
@@ -134,9 +140,9 @@ private async Awaitable RotateToRotation(Transform target, Quaternion targetRota
|
||||
|
||||
private async Awaitable PlayNode(DialogNode node)
|
||||
{
|
||||
// 화자 옆 DialogHud에 대사 표시
|
||||
// 화자 옆 DialogHud에 대사 표시 (배치 오프셋은 이 NPC의 설정값 사용)
|
||||
if (DialogHud.Instance != null)
|
||||
DialogHud.Instance.Show(node.Speaker, node.TalkText);
|
||||
DialogHud.Instance.Show(node.Speaker, node.TalkText, _hudChestHeight, _hudForwardOffset, _hudLateralOffset);
|
||||
|
||||
// 보이스 재생
|
||||
if (node.Voice != null && node.Speaker != null)
|
||||
|
||||
@@ -17,11 +17,16 @@ public class DialogHud : MonoBehaviour
|
||||
[SerializeField] private TMP_Text _speakerName;
|
||||
[SerializeField] private TMP_Text _dialogueText;
|
||||
|
||||
[Header("Placement")]
|
||||
[Header("Placement (기본값 — Show에서 오프셋을 안 넘길 때 폴백)")]
|
||||
[SerializeField] private float _chestHeight = 1.2f; // 화자 발 기준 가슴 높이
|
||||
[SerializeField] private float _forwardOffset = 0.5f; // 화자→플레이어 방향으로 띄울 거리
|
||||
[SerializeField] private float _lateralOffset = 0f; // 좌우 오프셋 (+ 플레이어 시점 오른쪽)
|
||||
|
||||
private Transform _speakerTransform;
|
||||
private float _activeChestHeight;
|
||||
private float _activeForwardOffset;
|
||||
private float _activeLateralOffset;
|
||||
private bool _placed; // 처음 한 번만 배치하고 이후엔 고정
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -35,9 +40,17 @@ private void OnDestroy()
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
// DialogHud 자체 기본 오프셋 사용
|
||||
public void Show(CharacterData speaker, string text)
|
||||
=> Show(speaker, text, _chestHeight, _forwardOffset, _lateralOffset);
|
||||
|
||||
// 배치 오프셋을 직접 넘겨 사용 (DialogPlayer가 NPC/씬별 값 전달)
|
||||
public void Show(CharacterData speaker, string text, float chestHeight, float forwardOffset, float lateralOffset)
|
||||
{
|
||||
_speakerTransform = speaker != null ? CharacterVoiceObject.Find(speaker)?.transform : null;
|
||||
_activeChestHeight = chestHeight;
|
||||
_activeForwardOffset = forwardOffset;
|
||||
_activeLateralOffset = lateralOffset;
|
||||
|
||||
if (_speakerName != null)
|
||||
_speakerName.text = speaker != null ? speaker.Name : string.Empty;
|
||||
@@ -53,10 +66,12 @@ public void Hide()
|
||||
if (_speakerName != null) _speakerName.text = string.Empty;
|
||||
if (_panel != null) _panel.SetActive(false);
|
||||
_speakerTransform = null;
|
||||
_placed = false; // 다음에 다시 뜰 때 재배치
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_placed) return; // 처음 위치에 고정 — 이후 플레이어가 움직여도 안 따라감
|
||||
if (_speakerTransform == null || Camera.main == null) return;
|
||||
|
||||
var camTr = Camera.main.transform;
|
||||
@@ -67,10 +82,13 @@ private void LateUpdate()
|
||||
if (toCam.sqrMagnitude < 0.0001f) return;
|
||||
Vector3 dir = toCam.normalized;
|
||||
|
||||
Vector3 chestWorld = _speakerTransform.position + Vector3.up * _chestHeight;
|
||||
transform.position = chestWorld + dir * _forwardOffset;
|
||||
Vector3 right = Vector3.Cross(dir, Vector3.up); // 플레이어 시점 기준 오른쪽(수평)
|
||||
Vector3 chestWorld = _speakerTransform.position + Vector3.up * _activeChestHeight;
|
||||
transform.position = chestWorld + dir * _activeForwardOffset + right * _activeLateralOffset;
|
||||
|
||||
// 빌보드 — 캔버스의 -Z(읽는 면)가 카메라를 향하도록 +Z를 카메라 반대로
|
||||
transform.rotation = Quaternion.LookRotation(-dir);
|
||||
|
||||
_placed = true; // 한 번 배치 후 고정
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user