"Reprint" (iii) Unity4.6ugui Chinese course document-------Overview-ugui Basic Layout

Source: Internet
Author: User

Original first, please poke: (iii) Unity4.6ugui Chinese course document-------Overview-ugui Basic Layout

2, basiclayout

In this section we will see how the UI elements are positioned relative to the canvas. If you want to test yourself while reading, you can create an image using gameobject > UI > Image in the Game menu.

2.1 The Rect Tool

Each UI element is represented as a rectangular layout. You can manipulate this rectangle by using the Rect tool in the toolbar in the scene view . the Rect tool is used for Unity2d UI features and can in fact be used on even 3D objects.

Toolbar buttons with Rect Tool selected

The Rect tool can be used to move UI elements left and right, resize them, and rotate them. Once you choose (sometimes we want to select a UI element in the object list) , you can move it by clicking and dragging anywhere within the rectangle. You can resize it by clicking and dragging on the edge or diagonally. The element can be left slightly out of the corner by hovering the cursor until the mouse cursor indicates that the rotation symbol rotates. You can then click and drag to rotate in either direction. This is the selected state:

Like other tools, theRect tool uses the current pivot mode and space to set pivot and Local in the toolbar . It's usually a good idea to work with the UI.

Toolbar buttons set to Pivot and Local

2.2 Rect Transform

Rect transform is a new transform component that is used for all UI elements, not regular transformation components.

Rect transforms has a position position, a rotation rotation, and a scaled scale , just like a regular transform, but it also has a width and height that is used to specify the size of the rectangle. So the relationship between high and scaled scale is: Usually the UI elements are pictures, then the original pixel size of the picture we set to this high-width, scaling is on this basis for the chant.

2.2.1 resizing Versus Scaling

When the Rect tool is used to change the size of an object, the sprites and 3D objects that are typically in the 2D system change the local scale of the object . However, when it uses the Rect Transform on an object , it changes the width and height , andThe local scale remains unchanged. This resizing does not affect the font size, the boundaries of the slice image, and so on.

2.2.2 Pivot

Rotation rotations, size sizes, and scale scales are all around this pivot, so the position of this axis will affect the rotation, resizing, or scaling effect. When the toolbar pivot button is set to pivot mode, you can move the pivot pivot of a Rect transform in the scene view to set the position of the pivots. Hoop :

2.2.3 Anchors

The Rect transforms includes a layout concept called the anchors anchor point. The anchor points as shown below in the scene view are four small triangular handles and the anchor point information is also displayed in the Inspector inspector.

If the parent object's rect Transform is also a rect Transform, then the child object can anchor its own rect Transform in various ways to the parent object's rect Transform. For example, a child object can be anchored to the center of the parent object, or to a corner. Anchoring also allows sub-objects to stretch to a certain scale relative to the parent width or height.

The UI element is anchored to the center of the parent. The element maintains a fixed offset to the center. (see four small triangles)

The UI element is anchored to the lower-right corner of the parent. The element remains at a fixed offset to the lower-right corner. (see four small triangles)

The corners of each rectangle are anchored to the parent rectangle, using one of these anchor points. You can drag the individual one of the anchor points, or if they are together you can drag them together and click and drag between them. If you hold down the SHIFT key while dragging the anchor point , the corresponding corner of the rectangle moves with the anchor point.

In the Inspector inspector, you can find the Anchor preset button in the upper-left corner of the rectangle transform component. Clicking the button pops up the Anchor preset drop-down list. From here you can quickly choose from some of the most commonly used anchoring options. You can anchor UI elements to the sides or the middle of the parent, or stretch with the parent object. Horizontal and vertical anchoring is independent.

The Anchor preset button displays the preset options for the currently selected (if any). If the anchor point is different from any preset position in either horizontal or vertical axis settings, the Custom option is displayed.

You can click the Anchor preset button below the small extension arrows to display the number of anchor points and pivot fields. min and max correspond to four small triangles. The option Lock rect can find the extended information on the right, and if there is no lock, it has the same functionality to hold down the SHIFT key while moving the anchor point in the scene view .

Each anchor handle has a fixed offset to the upper-left corner of the object's relative angle that is the top-left anchor handle with a fixed offset to the UI object. The pivot defines the position of the object relative to the anchor, and the location of the anchored point, Rect Transform component will display different fields. When all the anchor handle points are displayed together the fields are pos X, pos Y, Width, and height, but when the anchor is detached then the field can be changed partly or completely to the top, bottom, left, and right. This change depends on the location of the anchor and the definition of each corner filled into its respective anchor handle. A useful feature of anchor handles is that they automatically snap to other game object anchors, allowing precise positioning.

"Reprint" (iii) Unity4.6ugui Chinese course document-------Overview-ugui Basic Layout

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.