您现在的位置是:首页 >技术交流 >unity inputField计算文本高度网站首页技术交流
unity inputField计算文本高度
简介unity inputField计算文本高度
private float countTextHeight()
{
InputField inputField = talkBox.transform.GetComponent<InputField>();
TextGenerator m_TextGenerator = inputField.textComponent.cachedTextGenerator;
TextGenerationSettings settings = inputField.textComponent.GetGenerationSettings(new Vector2(inputField.GetComponent<RectTransform>().rect.width, 0));
settings.fontSize = playerInputTextSize;
settings.lineSpacing = 1;
settings.verticalOverflow = VerticalWrapMode.Overflow;
float height = m_TextGenerator.GetPreferredHeight(inputField.text, settings);
return height;
//inputField.GetComponent().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); }
//return 1f;
}
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。