通过检测每行字符所占据的总宽度,就可以判定所需的text对象、字体是否可以缩放
private void GetRowTextWordWidth(Text text)
{
string[] textArray = text.text.Split('\n');
float width = 0;
for (int i = 0; i < textArray.Length; i++)
{
TextGenerator tg = text.cachedTextGeneratorForLayout;
TextGenerationSettings settings = text.GetGenerationSettings(Vector2.zero);
width = tg.GetPreferredWidth(textArray[i], settings) / text.pixelsPerUnit;
Debug.Log("该行字体宽度为:"+width);
}
}