NGUI in unity
Last week I started my internship job as a unity software engineer. My main job is test and modify the existing program, and adjust the UI system based on unity. I will write down some of my work detail and something I learn from my work here as a record.
The first project that I involved in is about NGUI and UDP protocol in unity. There was a UI system that was built on NGUI system, and used the UDP protocol to communicate with the client. I have used UGUI system in my own game, but had never used NGUI. I have heard that UGUI was developed by the same develop team as NGUI, but I did not have any other understanding of it.
The first difference that I found between NGUI and UGUI is that there is a strict atlas system in NGUI, while that is nearly not exist in UGUI. When I used the UGUI formerly, I did not even have the concept of atlas, I can put an image into the assets, set it to the sprite type, and use it directly in the image or other components. But in NGUI, after I import a set of images, I have to use atlas maker to generate an atlas to manage all the images, and every use of those images should be based on atlas. I was not used to this situation until now, because if I want to change an image of NGUI, I should import the new image, change its type, and edit the atlas—but in this process, unity really costs a long time to update the changes of atlas. That’s really inconvenient. Actually I do not understand why should NGUI use this atlas to collect all the images as a prefab, I can also manage them efficiently with different folders, and that’s obviously faster. Maybe it is because of the underlying architecture of NGUI codes which I have not read.
![]() |
| The Atlas Maker Window |
![]() |
| Really Cost A Lot Of Time |
I also learned the concept of anchors in NGUI system. Anchors also exist in UGUI, but because of the volume and demand of games that I have made with unity before, I often choose a fixed resolution, so I can arrange UI in editor without anchors simply and the players can see the same things as I see in the editor. But the project that I was handling with need to be applied in multiple resolution, which means I have to choose “Free Aspect” in the game window to test the project. In this situation, I have to do something to avoid UI get deformed or even just disappeared in my screen—and that is actually what the anchors can do.
![]() |
| Anchors Window In NGUI |
Anchors in UGUI and NGUI are nearly the same. They can redefine the coordinate system of UIs, to fix the distance between a UI component and the edge of the screen(or the center of the screen) to avoid unexpected UI deformation. But in NGUI, settings of anchors seems to be more inconvenient than that in UGUI, with different anchor types and parameters such as execute timing. But this also means maybe anchors in NGUI are more customizable—while I still prefer UGUI. Anyway, considered that NGUI is a respectively old system and is gradually being replaced by UGUI, I think UGUI is more accessible for me.
Additionally, I found that I can delegate event to a NGUI button in scripts, instead of in the inspector window, and in that way, I can make the whole project more “safe”—for parameters in inspector window are really easy to get changed by the others, also sometimes it is possible to report the error “NullReferenceException”, for sometimes I forget to give the button object reference an instance of an object.
Delegating event to a button:
btn = this.GetComponent<UIButton>();
EventDelegate ed = new EventDelegate(this, "BtnMove");
btn.onClick.Add(ed);
![]() ![]() |
| Before And After Start |





评论
发表评论