using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace OTGIntegrated.Dialogue { public sealed class DialogueUI : MonoBehaviour { public GameObject panelRoot; public Text speakerText; public Text lineText; public Transform responseRoot; public Button closeButton; public Font uiFont; private readonly List spawnedResponses = new List(); private void Awake() { ConfigureResponseLayout(); if (closeButton != null) { closeButton.onClick.RemoveAllListeners(); closeButton.onClick.AddListener(() => FindObjectOfType()?.EndDialogue()); } Hide(); } public void Show(string speaker, string line, IReadOnlyList choices) { if (panelRoot != null) { panelRoot.SetActive(true); } if (speakerText != null) { speakerText.text = speaker; } if (lineText != null) { lineText.text = line; } ClearResponses(); if (choices == null || responseRoot == null) { return; } for (int i = 0; i < choices.Count; i++) { CreateChoiceButton(choices[i]); } } public void Hide() { ClearResponses(); if (panelRoot != null) { panelRoot.SetActive(false); } } private void CreateChoiceButton(DialogueChoice choice) { if (choice == null) { return; } GameObject root = new GameObject("DialogueChoice", typeof(RectTransform), typeof(Image), typeof(Button)); root.transform.SetParent(responseRoot, false); spawnedResponses.Add(root); root.GetComponent().sizeDelta = new Vector2(0f, 42f); LayoutElement layoutElement = root.AddComponent(); layoutElement.preferredHeight = 42f; layoutElement.minHeight = 42f; layoutElement.flexibleWidth = 1f; root.GetComponent().color = new Color(0.11f, 0.14f, 0.18f, 0.94f); Text label = CreateText(root.transform, "Text", choice.Text, 16, TextAnchor.MiddleLeft); label.rectTransform.anchorMin = Vector2.zero; label.rectTransform.anchorMax = Vector2.one; label.rectTransform.offsetMin = new Vector2(14f, 0f); label.rectTransform.offsetMax = new Vector2(-8f, 0f); Button button = root.GetComponent