31 lines
946 B
C#
31 lines
946 B
C#
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class ToolInfoTips : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI itemText;
|
|
public RectTransform bg;
|
|
public void ShowTips(string Item, Vector3 pos)
|
|
{
|
|
gameObject.SetActive(true);
|
|
itemText.text = Item;
|
|
GetComponent<RectTransform>().position = pos;
|
|
AdjustImageWidth(itemText);
|
|
}
|
|
|
|
public void HideTips()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
/// <summary>
|
|
/// 根据文字数量改变 背景 大小
|
|
/// </summary>
|
|
/// <param name="contentText"></param>
|
|
private void AdjustImageWidth(TextMeshProUGUI contentText)
|
|
{
|
|
float preferredWidth = contentText.preferredWidth;
|
|
bg.sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : 30), bg.sizeDelta.y);
|
|
contentText.GetComponent<RectTransform>().sizeDelta = new Vector2(preferredWidth + (contentText.text == "" ? 0 : 30), 52);
|
|
}
|
|
} |