public static float GetPreferredTextHeight(this RectTransform trans, Text text)
{
if (text == null) return 0;
var settings = text.GetGenerationSettings(new Vector2(trans.rect.size.x, 0.0f));
return text.cachedTextGeneratorForLayout.GetPreferredHeight(text.text, settings) / text.pixelsPerUnit;
}