Ngui Structure UI Root (2D) for creating a UI UI object with a camera parameter of simple 2D

Source: Internet
Author: User

Ngui Structure UI Root (2D) for creating a UI UI object with a camera parameter of simple 2D

The camera parameter created with Ngui is a simple 2D UI that generates 1 game objects named UI Root (2D) in the game's scene, with 3 other objects under it: Camera, Anchor, and Panel,1-4. This section describes each of the 4 game objects selected from Ngui from beginner to actual combat.


Figure 1-4 Viewing the newly created UI game object in the hierarchy view

1.4.1 UI Root (2D)

This game object will be responsible for controlling the size of the UI control. Select the UI Root (2D) object in the hierarchy view and view the components on this game object in the Inspector view, as shown in 1-5.


Figure 1-5 Viewing the components of the UI Root (2D) object in the Inspector View

Transform components are common in Unity's game objects, or all of the game objects have this component, which is not normally introduced. The Uiroot (Script) component is unique to this game object, and its properties and descriptions are as follows:

Q Scaling Style: You can use to modify the zoom style of a UI control.

Tip: There are 3 optional parameters under this property: Pixelperfect, Fixedsize, and Fixedsizeonmobiles.

2 Pixelperfect will ensure that the specified pixel size is always maintained regardless of the game resolution in the UI control. For example, if you specify a pixel size of 300x200, the game will be very large at the resolution of the image, and the UI control will be small at 1920x1080 resolution.

2 Fixedsize will ensure that the UI control always retains the specified size ratio in the game view, regardless of the game resolution. That is, the UI control scales proportionally as the game view is scaled.

2 Fixedsizeonmobiles will ensure that the UI control, while on the mobile device, remains the specified size ratio, while on other devices, the specified pixel size is maintained.

Q Manual Height: When the zoom style of a UI control is fixedsize, this property determines whether the UI control needs to scale proportionally. For example, when the game view is taller than the value set by this property, the UI control zooms in proportionally, and when the height is less than the value, the UI control shrinks proportionally;

Tip: When the UI control is scaled, the control's aspect ratio is constant.

Q Minimum Height: When the zoom style of the UI control is Pixelperfect, this property specifies the minimum height of the game view, and when the game view's height value is less than the set value of the property, the UI control is scaled down actively;

Q Maximum Height: When the UI control's zoom style is Pixelperfect, this property specifies the maximum height of the game view, and when the game view's height value is greater than the setting value of the property, the UI control is actively scaled up;

Tip: The resolution scale of the game view is varied, and the UI controls decide whether to scale the control only on a high level, so it is possible that the UI control may be "clipped" by the view at different game resolution scales. In order to cope with this situation, it is recommended that readers use two methods to avoid it.

Method One: Set the UI control to square, that is, the UI control width and height are the same;

Method Two: Specify the resolution scale of the game for the game view. The specified method is to click Edit| in Unity Project settings| The player command pops up a dialog box named Playersettings, shown in 1-6.


Figure 1-6 Playersettings dialog box

Expand the resolution and Presentation Property Group in the Playersettings dialog box, set the supported Aspect ratios property in it, as shown in 1-7.


Figure 1-7 Resolution and Presentation attribute group

Unity's default supported game views are many, such as 4:3, 16:10, and so on, if you want the game can only be run at the rate of 4:3, the other resolution of the complex selected from Ngui from the beginning to the actual combat.

Ngui Structure UI Root (2D) for creating a UI UI object with a camera parameter of simple 2D

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.