new_10007_YanCheng_Metrology/Assets/Template/Scripts/MyTools/Utilitys.cs

26 lines
901 B
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
/// <summary>
/// 封装一些常用得方法
/// </summary>
public static class Utilitys
{
public static string Split(string info)
{
string[] parts = info.Split('_');
return parts.Length >= 3 ? string.Join("_", parts[2], parts[3]) : "";
}
/// <summary>
/// 根据文字数量改变 背景 大小
/// </summary>
/// <param name="contentText"></param>
public static 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);
}
}