在 Unity 中,我尝试获取文本组件的大小,而不是 TMP,它具有水平溢出:wrap 和垂直溢出:overflow。
当文本量超出矩形宽度并添加新行时,text.preferredHeight 可以正常工作。它返回新行的高度。
但是 text.preferredWidth 返回了一个错误的值。它就像水平溢出一样,无论它实际上是什么。
我想要获得应用换行的值。
chat.text = 'looooooooooooooooooooooong word'; //text is wrapped. Extra line is created
Debug.Log(chat.perferredWidth); // returns wrong value. Extra line is not applied
Debug.Log(chat.perferredHeight); // returns correct value.