简体   繁体   English

如何改变扩展垂直布局组unity3d的方向?

[英]How to change direction of expanding vertical layout group unity3d?

When I`m adding new elements on vertical layout group and when there is no more place to them vertical layout group starting to expand downstairs.当我在垂直布局组上添加新元素时,当它们没有更多位置时,垂直布局组开始向楼下扩展。 How to make them adding from the top of each other?如何让他们从彼此的顶部添加?

What do I want:我想要什么:

  • 4th element第四元素
  • 3th element第三元素
  • 2nd element第二个元素
  • 1st element第一个元素

First element is always downstairs, next elements are spawning at top of it.第一个元素总是在楼下,下一个元素在它的顶部产生。

Thanks.谢谢。

Ok, I found one solution.好的,我找到了一个解决方案。 Idk if it is correct, but it is the simpliest one. Idk 如果它是正确的,但它是最简单的。 Just need to rotate "Rect tranform" for 180 degrees.只需将“Rect tranform”旋转 180 度即可。 Solution in image图像中的解决方案

The video of the result: google drive .结果的视频: google drive

    yourGameObject.transform.SetAsFirstSibling(); is the solution.

Can be done at the end of other transform actions.可以在其他转换操作结束时完成。

    button.transform.parent = ServerMessagesContent.transform;
    button.transform.position = ServerMessagesContent.transform.position;

    button.transform.SetAsFirstSibling();

In the Vertical layout group (component) you can change the Child Alignment to Lower Center.Vertical 布局组(组件)中,您可以将Child Alignment更改为Lower Center。

Rotating the whole UI element is not a good idea(might cause major headache down the line) and since this thread is the first thing that came up while googling, I felt I should drop this here for future devs.旋转整个 UI 元素不是一个好主意(可能会导致严重的问题)并且因为这个线程是谷歌搜索时出现的第一件事,我觉得我应该把它放在这里以供未来的开发人员使用。

Rotation is the worst possible thing which I can do to make my things spawn from bottom to top and child alignment will not help you either instead make a list, put all the things which need to be spawned and reverse the list and spawn.旋转是我能做的最糟糕的事情,它使我的东西从下到上生成,而孩子 alignment 也不会帮助你,而是列出一个列表,把所有需要生成的东西都倒过来,然后反转列表和生成。 It worked for me它对我有用

The easiest way is - assuming you're using a script to add objects to the parent - is just to assign the child index in the script so that each new entry appears above the last instead on below.最简单的方法是 - 假设您正在使用脚本将对象添加到父级 - 只是在脚本中分配子索引,以便每个新条目出现在最后一个条目之上而不是下方。

Documentation can be found here: https://docs.unity3d.com/ScriptReference/Transform.SetSiblingIndex.html文档可在此处找到: https://docs.unity3d.com/ScriptReference/Transform.SetSiblingIndex.html

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

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