24 lines
616 B
C#
24 lines
616 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class TMPAutoResize : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI tmpText;
|
|
public RectTransform rectTransform;
|
|
private void Awake()
|
|
{
|
|
if (tmpText == null)
|
|
tmpText = GetComponent<TextMeshProUGUI>();
|
|
if (rectTransform == null)
|
|
{
|
|
rectTransform = GetComponent<RectTransform>();
|
|
}
|
|
}
|
|
public void UpdateText(string newText)
|
|
{
|
|
tmpText.text = newText;
|
|
Canvas.ForceUpdateCanvases();
|
|
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, tmpText.preferredHeight);
|
|
}
|
|
}
|