You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
有个疑问,为什么用sizeDelta 来计算文本宽度,这个矢量计算在锚点(0.5,0.5,0.5,0.5)可以正确表示文本宽高,但是在其他情况下计算出来的是边距向量,这时候文本宽高就计算出错了,还可能出现负值。
稍作修改似乎就没问题了但是这么做是否有其他的一些地方没考虑到的 修改位置是下面Modify
public override float preferredWidth
{
get
{
var settings = GetGenerationSettings(Vector2.zero);
float width = cachedTextGeneratorForLayout.GetPreferredWidth(m_Text, settings) / pixelsPerUnit;
return width < rectTransform.rect.width || horizontalOverflow == HorizontalWrapMode.Overflow ? width : rectTransform.rect.width; //Modify
}
}
public override float preferredHeight
{
get
{
var settings = GetGenerationSettings(new Vector2(rectTransform.rect.size.x, 0.0f));
float height = cachedTextGeneratorForLayout.GetPreferredHeight(m_Text, settings) / pixelsPerUnit;
return height < rectTransform.rect.height || verticalOverflow == VerticalWrapMode.Overflow ? height : rectTransform.rect.height ;//Modify
}
}