using UnityEngine; using UnityEngine.UIElements; // 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; } 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; _document = GetComponent(); } // 시작 시 숨김 (이 시점엔 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("DialogField"); _speakerName = root.Q