unity NGUI tutorial layout system

To help you create UIs easier, NGUI features a flexible layout system that makes it easy to create widgets that position and resize themselves based on other widgets or even 3D objects.

To make use of this, have a look at the Anchors section under any widget in the Inspector view.  Try it with this label, for example.  If you select it, you will notice that it's not anchored, meaning that it will always stay where you left it.  However it has two children that are anchored to it.  This means that when the label's dimensions change, so will the position and size of the children.

Try it -- hit the Play button and watch what happens as the Typewriter effect gradually fills this label's text.

The system itself is deceptively simple.  Each of the 4 sides (left, right, top and bottom) has a pair of values -- relative, and absolute -- although with the default Unified option only the Absolute values are visible.  The formula that uses them is simple as well:

Final Position = Target [Width or Height] * Relative + Absolute


///


来帮助您创建ui更加容易,同时提供一个灵活的布局系统,让用户可以更方便地创建基于其他小部件的部件位置和调整自己,甚至3d对象。


利用这一点,看看锚部分在任何部件在Inspector视图。例如,尝试用这个标签。如果你选择它,你会注意到它不是固定的,这意味着它将永远呆在你离开它。然而,有两个子对象,锚定。这意味着,当标签的尺寸变化,所有子对象的位置和大小变化。


试一试——点击播放按钮,看会发生什么打字机效应逐渐填满这个标签的文本。


系统本身很简单。每个4边(左,右,顶部和底部)有一对值,相对和绝对——尽管使用默认统一选项只有绝对值是可见的。他们使用的公式很简单:


最终位置相对=目标(宽度或高度)* +绝对

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值