简体   繁体   English

如何在不旋转的情况下改变 Unity 中 VerticalLayoutGroup 的扩展方向?

[英]How change expanding direction of VerticalLayoutGroup in Unity without rotating?

I need to change the expanding direction of the VerticalLayoutGroup.我需要更改 VerticalLayoutGroup 的扩展方向。 With the default behavior the group will expand downstairs.使用默认行为,该组将扩展到楼下。 What i want is, that the group will expand upstairs.我想要的是,该小组将扩展到楼上。

The expected behavior is described in this Video .视频中描述了预期行为。 (Link to the answer on stackoverflow https://stackoverflow.com/a/43192904/11236801 ) (链接到 stackoverflow https://stackoverflow.com/a/43192904/11236801上的答案)

The solution on the link is, to rotate the LayoutGroup about 180°.链接上的解决方案是将 LayoutGroup 旋转约 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.所建议的解决方案这一个不会放弃在视频中显示的预期行为。

I added the ContentSizeFitter to the LayoutGroup like described in this link in the Unity Answers .我将 ContentSizeFitter 添加到 LayoutGroup 中,如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?是否有任何解决方案可以在不旋转 LayoutGroup 的情况下完成所需的行为?

Edit: I also noticed a downside from the rotating approach: The Billboard Script from the MixedRealityToolkit will force the LayoutGroup to rotate back to 0°.编辑:我还注意到旋转方法的一个缺点:来自MixedRealityToolkit的 Billboard 脚本将强制 LayoutGroup 旋转回 0°。

This works for me:这对我有用:

Unity Inspector 截图

Note the Child Alignment setting on the Vertical Layout Group , and the Pivot settings on the Rect Transform .注意Vertical Layout Group上的Child Alignment设置和Rect Transform上的Pivot设置。 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.另请注意Content Size Fitter组件的存在,并将其Vertical Fit设置为Preferred Size ,这将在添加或删除内容时调整布局组的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM