返回值为长度
private float CalcTextWidth(Text text)
{
TextGenerator tg = text.cachedTextGeneratorForLayout;
TextGenerationSettings setting = text.GetGenerationSettings(Vector2.zero);
float width = tg.GetPreferredWidth(text.text, setting) / text.pixelsPerUnit;
Debug.Log("width = " + width.ToString());
return width;
}