using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using System; using UnityEngine.UI; public class UIDialog : MonoBehaviour { [SerializeField] private string dialogTitle; [SerializeField] private TextMeshProUGUI dialogTitleHandle; [SerializeField] private RectTransform contentHandle; /// TABS [SerializeField] private float tabWidth = 50f; [SerializeField] private float tabHeight = 16f; // List of dialog tabs private List dialogTabs; /// ENTRIES private List entries; private float entryHeight = 20f; private float entryIndentWidth= 10f; private List cleanupPool; private bool isOpen; // Start is called before the first frame update public virtual void Start() { dialogTitleHandle.text = dialogTitle; dialogTitleHandle.font = UIManager.Instance.Font; isOpen = gameObject.activeSelf; dialogTabs = new List(); entries = new List(); cleanupPool = new List(); } internal RectTransform GetContentHandle() { return contentHandle; } public bool IsOpen() { return isOpen; } protected virtual void OnEnable() { isOpen = true; } protected virtual void OnDisable() { isOpen = false; } public float GetTabWidth() { return tabWidth; } public float GetTabHeight() { return tabHeight; } /// /// Returns the height of the dialog title bar /// public float GetTitleBarHeight() { return dialogTitleHandle.rectTransform.sizeDelta.y; } /// /// Adds a new tab to the dialog, when clicked it will call the given callback /// public void AddDialogTab(string tabName, Action onClick) { dialogTabs.Add(AddTabButton(tabName, onClick)); } /// /// Add the tab button to the right of the existing tabs /// private GameObject AddTabButton(string tabName, Action onClick) { GameObject tabButton = new GameObject("TabButton", typeof(RectTransform)); tabButton.transform.SetParent(transform); // worldPositionStays ? // RectTransform anchors to the right of the content handle RectTransform rTransform = tabButton.GetComponent(); rTransform.anchorMin = new Vector2(0, 1); rTransform.anchorMax = new Vector2(0, 1); rTransform.pivot = new Vector2(0, 1); rTransform.sizeDelta = new Vector2(tabWidth, tabHeight); // Count tabs * tabSize to get the position from the left rTransform.anchoredPosition = new Vector2(tabWidth * dialogTabs.Count, -(GetTitleBarHeight())); // Add the onClick callback to the button Button button = tabButton.AddComponent