ND_SimulationAutomaticControl/Assets/Scripts/UI/UIPanel/UI_TopTipPanel.cs

44 lines
1.4 KiB
C#

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<TextMeshProUGUI>("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();
}
}
/// <summary>
/// Ãæ°åÏûʧ
/// </summary>
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<RectTransform>().sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : width), height);
}
}