private void refreshContentSizeFitters()
{
// 获取 contentParent 下的所有 ContentSizeFitter 组件
ContentSizeFitter[] contentSizeFitters = gameObject.GetComponentsInChildren<ContentSizeFitter>();
for (int i = 0; i < contentSizeFitters.Length; i++)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(contentSizeFitters[i].GetComponent<RectTransform>());
}
VerticalLayoutGroup[] verticalLayouts = gameObject.GetComponentsInChildren<VerticalLayoutGroup>();
for (int i = 0; i < verticalLayouts.Length; i++)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(verticalLayouts[i].GetComponent<RectTransform>());
}
HorizontalLayoutGroup[] horizontalLayouts = gameObject.GetComponentsInChildren<HorizontalLayoutGroup>();
for (int i = 0; i < horizontalLayouts.Length; i++)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(horizontalLayouts[i].GetComponent<RectTransform>());
}
}
标签:int,gameObject,刷新,verticalLayouts,Unity,horizontalLayouts,contentSizeFitters,Get
From: https://blog.51cto.com/u_14359474/8947878