47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
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<TextMeshProUGUI>("Text_Title");
|
|
text_Content = GetControl<TextMeshProUGUI>("Text_Content");
|
|
bg = GetControl<Image>("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);
|
|
}
|
|
/// <summary>
|
|
/// Ãæ°åÏûʧ
|
|
/// </summary>
|
|
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<RectTransform>().sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : width), height);
|
|
}
|
|
}
|