何在不旋转的情况下更改Unity中VerticalLayoutG

何在不旋转的情况下更改Unity中VerticalLayoutG

本文介绍了如何在不旋转的情况下更改Unity中VerticalLayoutGroup的扩展方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改VerticalLayoutGroup的扩展方向.使用默认行为,该小组将在楼下展开.我想要的是,该小组将扩大到楼上.

I need to change the expanding direction of the VerticalLayoutGroup.With the default behavior the group will expand downstairs.What i want is, that the group will expand upstairs.

视频中描述了预期的行为.(链接到关于stackoverflow的答案 https://stackoverflow.com/a/43192904/11236801 )

The expected behavior is described in this Video.(Link to the answer on stackoverflow https://stackoverflow.com/a/43192904/11236801)

链接上的解决方案是将LayoutGroup旋转约180°.现在这似乎更像是一种解决方法,因为所有子项也必须轮换.此解决方案建议的解决方案将无法提供视频中显示的预期行为.

The solution on the link is, to rotate the LayoutGroup about 180°.Now this seems more like a workaround, because all childs have to be rotated as well.The solution suggested by this one will not give the expected behavior shown in the video.

我已按照统一答案.现在,LayoutGroup将在两个方向(楼上和楼下)扩展.

I added the ContentSizeFitter to the LayoutGroup like described in this link in the Unity Answers. Now the LayoutGroup will expand in both directions (upstairs and downstairs).

有什么解决方案可以在不旋转LayoutGroup的情况下实现所需的行为?

Is there any solution to accomplish the desired behavior without rotating the LayoutGroup?

我还注意到轮换方法的缺点: MixedRealityToolkit 中的广告牌脚本将强制LayoutGroup旋转回0°.

I also noticed a downside from the rotating approach:The Billboard Script from the MixedRealityToolkit will force the LayoutGroup to rotate back to 0°.

推荐答案

这对我有用:

请注意Vertical Layout Group上的 Child Alignment 设置,以及Rect Transform上的 Pivot 设置.当添加更多项目时,这会使布局组向上扩展.
另请注意,存在一个Content Size Fitter组件,并且其 Vertical Fit 设置为 Preferred Size ,当添加或删除内容时,该组件将调整布局组的高度.

Note the Child Alignment setting on the Vertical Layout Group, and the Pivot settings on the Rect Transform. This makes the layout group expand upwards when more items are added.
Also note the presence of a Content Size Fitter component, and its Vertical Fit set to Preferred Size, that will adjust the height of the layout group when content is added or removed.

这篇关于如何在不旋转的情况下更改Unity中VerticalLayoutGroup的扩展方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:57