unity NGUI Example1 Anchors

来源:互联网 发布:君子知怕分析 编辑:程序博客网 时间:2024/05/29 05:00
This example shows how to use anchors.

All widgets are capable of anchoring themselves to another widget, or even a random Transform somewhere in the world.

To anchor a widget, choose the anchor type under the Anchors section and drag & drop the object you want it to be anchored to.

For an easiest example, start with the Uniform anchor. Uniform anchor simply means the same target object is used for all 4 sides.

An Advanced anchor lets you choose 4 sides individually. Remember: you don't have to specify all 4! For example if you wanted a label to have an adjustable height and width anchored to top-left, then do just that -- set its Top and Left anchors, but leave Right and Bottom alone. Set the label to "Resize Freely" and give it a top-left pivot point, and you're done.

If you want more control, Custom anchor setting let you combine relative and absolute offsets to achieve the desired result. Relative value of 0.5 means "center", for example, while 0.25 means 25% of the width (for left and right) or height (for top and bottom). The formula is: Final Size = Target's Size * Relative + Absolute.

If you want to anchor a widget to a 3D object, make sure that only one camera is able to draw it by setting its culling mask, or NGUI may not be able to find the correct one. Other than that, the process is the same: just drag & drop the target object into the Target field.


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

这个例子展示了如何使用锚点。


所有部件都能够将自己固定的另一个小部件上,甚至是随机变换在世界的位置。


选择锚点类型 拖到你想要固定的组件上。


对于这个简单的例子,统一锚点。统一锚点意味着相同的4边目标对象。


一个高级的锚点可以选择单独4边。记住:你不需要指定所有4边 !例如,如果你想要一个标签有一个可调的高度和宽度左上的锚定,然后做到这一点——设置它的顶部和左锚,但是别管正确和底部。自由设置标签为“调整”,并给它一个左上的轴心点,你就完成了。


如果你想要更多的控制、自定义锚点设置让你结合相对和绝对补偿来实现所需的结果。相对的值为0.5时表示“中心”,例如,当0.25意味着25%的宽度(左和右)或者高度(顶部和底部)。公式是:最终大小=目标的大小*相对+绝对。


如果你想锚点部件3d对象,确保只有一个相机能够画它通过设置选择屏蔽,或同时仍可能无法找到正确的一个。除此之外,这个过程是一样的:只是拖&下降目标对象到目标字段。

0 0