using System.Collections; using System.Collections.Generic; using System.ComponentModel; using TMPro; using UnityEngine; using UnityEngine.UI; public class UI_TopTipPanel : BasePanel { public Image bg; public TextMeshProUGUI text_Content; public TextMeshProUGUI text_Title; public static UI_TopTipPanel instance; private void Start() { instance = this; } public void Init(string title, string content) { text_Title = GetControl("Text_Title"); text_Content = GetControl("Text_Content"); bg = GetControl("UI_TopTipPanelBG"); text_Title.text = title; text_Content.text = content; TextMeshProUGUI tempText = text_Title.preferredWidth > text_Content.preferredWidth ? text_Title : text_Content; AdjustImageWidth(tempText, bg.rectTransform, 30, 21); } /// /// Ãæ°åÏûʧ /// public void Hide() { StopCoroutine(HideAsync(5)); StartCoroutine(HideAsync(5)); } private IEnumerator HideAsync(float disappear) { yield return new WaitForSeconds(disappear); } public void AdjustImageWidth(TextMeshProUGUI contentText, RectTransform _bg, float width, float height) { float preferredWidth = contentText.preferredWidth; _bg.sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : width), _bg.sizeDelta.y); contentText.GetComponent().sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : width), height); } }