Hello everyone, I'm Qin Yuanpei. Welcome to follow my blog. My blog address is blog.csdn.net/qinyuanpei. The blogger has recently started to study NGUI, but to be honest, the bloggers feel that NGUI is somewhat scattered, because most of the information on the Internet is just a simple explanation of how to use NGUI, we have not explained the meaning of NGUI from the perspective of substantive principles. NET will only drag the control is the same, and cannot grasp the internal thing. Therefore, we recommend that you study NGUI with official examples. Over the past few days, bloggers have basically been looking at the NGUI sample program. I feel that the content is complicated. In today's article, bloggers will address the following questions:
1. NGUI anchor control
2. Hybrid use of Unity3D and NGUI
3. Unity3D model texture loss Solution
The following describes the content of today:
I. NGUI anchor control
In NGUI, the interface is divided into nine areas according to the following figure, which are top, bottom, left, top left, bottom left, top right, top right, bottom right, and middle. It is called the r anchor in NGUI. What are the advantages of using an anchor to control the interface layout? The advantage is that we can manage controls in the same region in one way, which can simplify our management. Imagine how complicated it would be if every control uses absolute coordinates for control. Through the anchor function provided by NGUI, we can use the relative coordinates in each anchor to determine the position of the control in the region. Now let's take this figure as an example to explain how to use NGUI's anchor function.
First, we use the interface tool provided by NGUI to create a 2D interface. we renamed Camera to 2 DUICamera, and then renamed the default Panel below to 2 DUiPanel, delete the default Anchor node. Next, we will create an empty game body under this node and use the Rest method to set its Position and Rotation (0, 0, 0). This step is very important, even if you need to modify its location. Then we use NGUI-> Attach-> Anchor to add a UiAnchor for it to become an Anchor and rename it Bottom_Anchor, this means that we will display the content at the Bottom of the screen under the node, so we need to set the Side in the UIAnchor script bound to the Node object to Bottom,
We set the coordinates of Anchor_Bottom to (0,-, 0). The parameter values here depend on the project. Next, we add an empty object under it and change it to Anchor_Offset. From the name, we can see that this is an object used to control the child control offset in this area, we set its position to (0, 40, 0), so that it is offset 40 to the origin of the region. next, add a Button under the node and set the Label value to Bottom. Similarly, we create an anchor for the remaining eight regions. The method is the same as the one above and is symmetric. We will not talk about it here, in this example, we want to tell you that when using NGUI, you should use the anchor to reasonably manage the interface elements in the game, so that we can better manage the interface, the final result is the image that was first displayed, and it will not be displayed here.
2. Hybrid use of Unity3D and NGUI
Unity3D game scenarios are divided into 2D and 3D. Let's talk about their hybrid use with NGUI respectively. First, for the 2D interface, we need to modify the default 2DUi structure. We need to put Anchor and Camera at the same level, that is, both belong to the 2DUI subnode. Second, set the camera depth of field on the 2D interface. This value must be greater than the depth of field value of the main camera in the scenario. Keep the default values for other parameters ., In this article [Unity3D] Unity3D Game Development's parkour game project explanation, the blogger used NGUI to show the number of gold coins and the distance between the players:
The 3D interface is very simple, because there is only one camera in the scene, so we can do it directly according to the usual method, but the NGUI unit seems to be different from the Unity unit, when setting the position, objects in NGUI usually need a large value to be moved to the target position. At present, we have not figured out the internal cause, the research by the bloggers will be added later in the article, but according to Xuan Yusong's blog, a numerical conversion is required, but the bloggers have not studied it clearly. The following is the effect of the combination of NGUI and Unity3D scenarios. We can find that the two can run perfectly in the same scenario:
3. Unity3D model texture loss Solution
The blogger is a research code, and design software only uses Photoshop and CAD, so there is basically no model or anything. Bo Master/Slave downloaded the 3DMax model on the Internet. After the result is exported to FBX format, the model texture is lost in Unity3D. The model surface material is the default gray material in Unity3D. After studying the problem for a long time, the author did not find the cause until he found a solution to the problem last night. I hope it will help you. First, we open 3 DMax and select our model-xiangjian Qixia Chuan Si Liu mengyi,
Next, choose rendering-> View image files, and locate the texture folder in the new dialog box. Generally, In the Textures folder at the same level as the model file, the texture format is dds, this format is not supported in Unity. Okay. Next, select the texture file one by one:
Click View to open the texture image and click the first button to save the texture.
Finally, go back to Unity3D, create a Textures folder under the file where the model is located, and copy the saved texture file to this directory. After the model is imported into Unity, a Materials folder is generated under the model directory. in this folder, we can see the material corresponding to the model and select a material:
After we set all the materials to textures, we will be able to see familiar figures in the scene, but how do we feel that the gap between the figures in the game is so big?
Well, thank you for your attention to my blog. It will be finished by today. Good night, haha, don't learn from me, I was forced by my roommates to do this.
Daily proverbs: Your life will never let you down. The wrong turns, the wrong paths, the tears, the dripping sweat, and the scars all make you unique. -- Zhu Xueheng
If you like my blog, please remember my name: Qin Yuanpei. My blog address is blog.csdn.net/qinyuanpei
Reprinted please indicate the source, Author: Qin Yuanpei, the source of this article: http://blog.csdn.net/qinyuanpei/article/details/25654647