Use of Unity3d self-combat development of racing game instances, key points of record (iii) of the UI menu production

Source: Internet
Author: User

I. Overview

Before the game UI menu is created, you have to design the level and style of the menu first. I am using unity5.01e, this version of Ugui has been very useful. Sure enough, I still like to use the official thing, feel very comfortable, although some components have not yet. I can't find the feel of that bunch of UI components in C #.

Two. UI Layout Key Technology 1.RectTransform

This is a characteristic component of Ugui, which is inherited from transform. It is equivalent to adding anchor data to the transform, and then it is more suitable for 2D UI interface development. The inner truth is still the treatment of transform.

The simple knowledge about Recttransfrom can be consulted
recttransform-Official Brochure
What I usually use is the position of the anchor point defined in the Rect tool. For example, to fix the container on the canvas, I use the extension anchor point anchors (Min (0,0) Max), the anchor point will be positioned in the parent control of Four Corners;
Set the title above, I will use the layout anchors (Min (0.5, 1) Max (0.5,1)). Anchors your own controls at the specified location in the parent control.

2.component->layout->*

In addition to the above anchor points, the most important thing is the layout series components in the component, my most commonly used is horizontal layout group and Vertical layout group. As the name implies, the horizontal layout combines vertical layout groups. Used to add in a target container to arrange the child controls in the container according to a certain layout.
For example, my menu:
First look at the effect

Look at hierarchy again.

is divided into three interfaces under a canvas:

1.MainMenu is the interface;
2.Settings is the setting interface;
3.Car Settings is the model selection/route selection interface that you enter after clicking Game mode
4.WaterImage is special, is a when entering the waterfall, the water drops on the screen.

Included header and buttons two in MainMenu
1.Header is the title of the anchor point I used is anchors (Min (0.5, 1) Max (0.5,1))
2.Buttons is four options, I use the vertical Layout Group, the four buttons are arranged in a vertical order.

About Vectical Layout Group, it has several properties:
1.Padding is the distance from the parent control to the top or bottom
2.Spacing is control spacing
3.Child Alignment is the control alignment
4.Child force Expand is whether to enforce the expansion of child controls to the maximum size that can be accommodated

3. Key events

Use the key event mode such as mfc/c#, always double-click the control, or the control. OnClick + = new Clickeventhandle (onclick) code addition method. Just beginning with unity is a bit of a fit. But now I get used to it.
Unity also has interface to add key functions and dynamic code to add listeners in two ways. See what you need.

1) graphical addition of key events

If the button is a simple function can actually be added with the interface. However, the disadvantage is that the parameters of the function can only be one and the parameters can not be too complex, such as parameter String/int/float/bool and other basic types. If you exceed this range, you will not see this function at all.
And the parameters of the completed function are not dynamic.

This way I don't say much, there are steps on the Internet.
is to add a new entry in the OnClick button property interface and drag the game object containing the target function to the left column of the entry (Circle 1), this time the game object contains all (this component must have a function that conforms to the interface display specification, Like some functions as parameters of a custom struct will not appear at all) the component will appear in the top right of the drop-down box (Ring 2), and then click the drop-down box to select the component, the selection will pop up the two menu bar Select Component function, after the function selection, in the bottom right input box (ring 3) fill in the parameters.

2) Adding events dynamically

The

Use of dynamic add listeners is good for code specification and is good for management.
For example, after I clicked on Racingmode and Timermode, I saved the current game mode to the configuration file, and I used to add listeners to the button dynamically:

//添加竞赛模式按钮的监听器RacingModeButton.onClick.AddListener(new UnityAction(SetGameTimerMode));//添加计时模式按钮的监听器RacingModeButton.onClick.AddListener(new UnityAction(SetGameRacingMode));privatevoidSetGameTimerMode(){//保存游戏模式“计时模式”到配置文件    ConfigurationManager.Instance.CurrentGameModel = ConfigurationManager.GameModel.TimerModel;}privatevoidSetGameRacingMode(){//保存游戏模式“竞赛模式”到配置文件    ConfigurationManager.Instance.CurrentGameModel = ConfigurationManager.GameModel.RacingModel;    }
UI Menu Toggle Mode

In fact, my main menu, the Setup menu, the model/route selection menu, are all panel, but hide the other menus that are not currently needed.
I only use the switch mode is the rotation switch. Is the a menu rotation is missing, the rotation is a b menu






That's the effect.
The way I do it is:
Setting the y of the current a menu rotation to 0 will need to hide the B menu rotation y to 90
And then when you rotate
Step1:a.rotation.eulerangle.y 0-90
STEP2:B.ROTATION.EULERANGLE.Y-90-0
Can
The code is as follows:

Currenttransform indicates that the current menu//nexttransform represents the next menu void Fixedupdate () {//Set Switchtag when you want to switch to0if (Switchtag = =0) {if (currenttransform. Eulerangles. Y< -) {Currenttransform. Rotate(Vector3. up, Switchspeed * Time. Deltatime);} else {//The menu is placed in a standard position after the rotation is complete currenttransform. Rotation= quaternion. Angleaxis(- -, Vector3. up);Nexttransform. Rotation= quaternion. Angleaxis(- -, Vector3. up);Set flag ready to rotate the next menu out Switchtag =1;}} if (Switchtag = =1) {if (nexttransform. Eulerangles. Y<0) {Nexttransform. Rotate(Vector3. up, Switchspeed * Time. Deltatime);} else {Nexttransform. Rotation. Eulerangles. Set(0,0,0);Next menu turn out complete, set flag end rotation Switchtag =-1;}        }    }

Use of Unity3d self-combat development of racing game instances, key points of record (iii) of the UI menu production

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.