using System.Collections; using System.Collections.Generic; using System.ComponentModel; using TMPro; using UnityEngine; public class UI_TopTipPanel : BasePanel { public RectTransform bg; public TextMeshProUGUI text_Content; public TextMeshProUGUI text_Title; public void Init(string title, string content,bool isHide) { GetControl("Text_Title").text = title; text_Content.text = content; TextMeshProUGUI tempText = text_Title.preferredWidth > text_Content.preferredWidth ? text_Title : text_Content; AdjustImageWidth(tempText, bg, 30, 21); if (isHide) { Hide(); } } /// /// Ãæ°åÏûʧ /// private 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); } }