Unity3d building an elegant UI framework

Source: Internet
Author: User

Why use the UI framework? Direct use of Ngui or Ugui a drag-and-drop directly from the interface is it OK?

I believe that a lot of small white, including I have just learned Unity3d UI in this way.

My first unity2d game, "Mountain Racer", uses the Ngui-equipped interface.

Weak network hand tour generally have no complicated interface, I also very easy to spend a day to put the interface installed, looks good pretty, but also spent a lot of time to do dynamic effects.

Once the interface is loaded, the game begins to develop, and the question begins:

1. How do I communicate between interfaces? For example, click the Back button, go back to the previous screen, click the Backpack system, eject the backpack.

2. How to communicate the interface with the game data? For example, click on the leaderboard to list the latest rankings, click to buy a car, can deduct money and buy new vehicles.

The first thing I did (and I believe most of the newbies liked the most) was to add a script for each UI that would trigger the feature, and then add a public gameobject,

Then drag into the object that you want to control when the UI is triggered. Implement the logic function in the onclick function of the script.

It's pretty easy to do that. Soon I also spent half a day dragging around and binding the various objects that the UI is associated with.

But the rest of the problem is really a headache for me:

1. with the complexity of the game system, more and more UI controls, the direct communication of each UI, and the communication between UI and Gameobject form a complex spider web,

Dragging and dragging, sometimes I forget which object is associated with which object. If someone wants to see my program, I guess he can't find a portal to the UI logic for half a day.

2. coupling is very serious, if you want to change the requirements, change a UI or change a game object, then you need to manually all the objects associated with the object changed again.

3. as an obsessive-compulsive disorder, I can't stand the confusion of program code. This kind of organization is very "not graceful", looks very disorderly.

In view of the above, I began to look for a new, scientific, efficient way of UI management,

The first thing that came to mind was the famous MVC pattern, and I wanted to use it to manage my UI, but because I wasn't very familiar with the MVC pattern, I tried it and it didn't work out very well.

Search on the Internet a few good UI framework, are written very good, you can refer to the reference:

Design and implementation of 1.unity-ui-framework by: Wang Xianyi Github

2. Simple, powerful ttuiframework By:chiuan game Bull (the design idea is to refer to the author above)

3. "Designing and developing a set of automated UI frameworks" By:npc Yan game Bull

Their design ideas are very clear, the effect is also very strong, are some of the game industry Daniel, but it is a bit complicated.

As a rookie, of course I want to design only the novice can understand things.

All right, nonsense, here are the two main directions that I've designed:

1. Design a set of frameworks for managing the UI, the creation, destruction, and switchover of each UI is accomplished through this manager. There is no direct contact between the various UIs.

2. Design a framework for managing messages that communicates between the UI and object through this manager, enabling decoupling between the UI and objects.

Not to be continued ...

Unity3d building an elegant UI framework

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.