赞
踩
using FitMode = UnityEngine.UI.ContentSizeFitter.FitMode;
public static Vector2 GetContentSizeFitterPreferredSize(this RectTransform rect,ContentSizeFitter contentSizeFitter)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
return new Vector2(HandleSelfFittingAlongAxis(0,rect,contentSizeFitter), HandleSelfFittingAlongAxis(1,rect,contentSizeFitter));
}
private static float HandleSelfFittingAlongAxis(int axis,RectTransform rect,ContentSizeFitter contentSizeFitter)
{
FitMode fitting = (axis == 0 ? contentSizeFitter.horizontalFit : contentSizeFitter.verticalFit);
if (fitting == FitMode.MinSize)
{
return LayoutUtility.GetMinSize(rect, axis);
}
else
{
return LayoutUtility.GetPreferredSize(rect, axis);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。