Unity:如何检查是否有未显示的文本

时间:2018-04-04 15:31:42

标签: c# unity3d

如何检查UI中是否有未显示的文字。 换句话说,显示输入文本所需的宽度大于显示此文本的游戏对象的宽度。

修改

以下答案是我需要的解决方案,但我有另一个相关的问题: 如果有溢出怎么知道最后显示的字符或第一个隐藏字符?

1 个答案:

答案 0 :(得分:3)

您可以尝试以下方法:

bool CheckTextWidth()
{
    float preferredWidth = LayoutUtility.GetPreferredWidth(text.rectTransform);
    float parentWidth = parentRect.rect.width;
    return (preferredWidth > (parentWidth-longestCharWidth));
}