Unity3d's Ugui:rect Transform and anchor

Source: Internet
Author: User

Rect Transform

As we all know, all gameobject in Unity3d have to carry a transform component, and the component cannot be removed, Then the gameobject shown as UI is not carrying transform, but using the Unity3d Rect transform component specifically designed for the UI component, as follows:

In addition, Canvas renderer is also the component that the UI component must carry.

Let's take a look at the features it provides for us:

Position

The position is in pixels, and its specific value is the anchor point, indicating the distance from the anchor point, where the x-axis from left to right values are increasing, the y-axis from bottom to top of the value of the larger, where the POS The position.z effect in Z and transform is the same, but this value is not used to represent the depth of the UI. Keeping this value is estimated to be a consideration of some effect implementations of the 3D UI.

Size

Unlike scaling, these two values set the dimensions of the UI, are negative and do not flip the UI but are not displayed directly.

Above two buttons, the top button is set width to 320, below is the width of the button is set to 160 scale X to 2.

Rotating

Effect with transform, generally with tween use.

Scaling

Effect with transform, generally with tween use.

Depth

Without the depth of the Ngui, the depth in the Ugui is fully represented by the tree structure, and the nodes at the bottom of the same level will overwrite the nodes at the top, as follows:

Modify the tree display list as follows:

Anchor

Rect Transform in addition to the functions mentioned above, it also provides a stroke function, which mainly implements the function of relative layout.

We can also configure the Strokes very intuitively:

The anchor points describe the location information of the parent object of the current UI. The anchor point represents the (0, 0) point of the current object's coordinates.

Non-stretch

We can find that there are left, Center, right, Top, middle and bottom six sets of items, these 6 items can be combined 9 forms of anchor points, respectively, corresponding to the current UI parent object in 9 directions position, so that our UI to make relative position adjustment, For example, when the UI coordinates are (0, 0), select Centermiddle the current UI is centered, and select TopLeft the UI is in the upper-left corner of the parent object.

Centermiddle:

TopLeft:

Stretch

In addition to the above, there is a stretch state, which represents the current UI distance from the edge of the parent UI, and when set, it uses a similar relative position to define the location and size of the UI, we look at:

When we select both horizontal and vertical stretch, pos X, pos Y, width, and height are changed to left, Top, right, and bottom, which are arranged using relative positions, so let's adjust to see.

We find that the button is always 10 pixels away from the parent, and resizing the parent modifies the dimensions of the child, as follows:

We find that the button is always rendered as a relative position.

Custom Anchor

We previously defined the anchor point is directly in the drop-down menu selection, then whether the anchor can be customized, the answer is yes, for example, when we need the following effect, we need to customize the anchor.

We want the size of the child UI to always be proportional to the size of the parent UI, for example, regardless of how large the parent UI is, the child UI occupies 10% of its space.

We only need to set the child UI anchor point to a suitable value, such as the size of the child UI, as follows:

We copy several changes in size to see the effect:

Pivot

The registration point is called the center point, and if anchor represents the location of the UI's parent, pivot represents the location of the (0, 0) point of the UI itself.

We first open pivot:

You can then modify the pivot of the UI in the scene, as follows:

This small blue circle is the center point of the button component, indicating the (0, 0) Point of the button component.

Let's look at an example:

I want to display a button at the top right of the screen with a 10 spacing between the buttons and the screen, just set the center point of the button to the top right, as follows:

Complementary Blueprint Pattern

Indicates whether the rotation of the object is ignored. The object can not be rotated by a point opening.

Rawedit mode

Indicates whether the position and dimensions of the UI will match according to anchor when the anchor is modified, and the point can be matched.

Original: http://www.cnblogs.com/hammerc/p/4837650.html

Unity3d's Ugui:rect Transform and anchor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.