Good day, friends!
Yes, yes, it’s friends, because after my
first post, there were a lot of people who were ready to help everyone with what they could. And in this I am overly grateful to Habra - two whole musical compositions have already been written and all the text in the game has been correctly translated into English. I do not even know what I would do without you!
But the post itself is not about that. Today I would like to share with you little tips about the user interface. About what should be avoided at the very beginning of development, and what to do next. Unfortunately, my "skill" is not high enough to write about something really new and unexplored in this area, so the post will be more devoted to newcomers to the game maiden (and first of all to those who are still afraid of NGUI), yes and the post will be subjective at all 146%.
')

So, the most important note when developing the interface when you work in
Unity3D : in no case do not use the standard interface! On the
Asset Store (this is such an inside-
Unity store, where people share their experiences and ready-made solutions) there is a huge variety of different GUI-systems, and
NGUI is the most popular at the moment. Do not underestimate it (or other GUI-systems), because the choice of this technology will save a lot of time.
Once upon a time, when I looked askance at
NGUI , I thought that the standard GUI is not so bad - know yourself, and prescribe areas for displaying buttons, and what they do ... A lot of time and effort was spent on this whole thing, and as it turned out, nothing!
The interface was too slow ... Very! According to the results of the work, it turned out that even one interface window is “calculated” as much as 25 ms (on the i5 notebook), which turned out to be totally unacceptable for the end user. And literally on the same day, when I drew attention to this,
NGUI began to be sold to
Asset Store with a big discount. It was then that everything changed.

The principle of operation of
NGUI (or any similar system) is that all GUI elements are simple objects that have their own material and even mobile phones are easily rendered without affecting performance. But it is here that one of the main “problems” arises (because of which I initially refused to
use NGUI ) - you have to display certain functions for handling events, such as pressing a button and the like.
In general, this is not a problem if you have an accurate idea that
"here I will have an exit button from the game, and here the options window will open .
" Problems will begin when you want to dynamically output a different number of elements and dynamically determine what to do with them. More problems are found when you find out that when you call a Callback function with a button in the
NGUI , the
NGUI cannot pass arguments to the function to start.
I found a rather elegant (and maybe crooked, someone like :)) solution, and it boils down to the following (everything written below concerns
Unity3D with
NGUI ):
Simply, in the name of the button object, write down all the arguments you want to use to call the callback functions. And when calling the Callback function, use this wonderful line:
UIButton.current.gameObject.name
in order to read the name of the just-pressed button. Simple, isn't it?
In order to write different arguments to the name of an object (that is, in fact, to form one line from different arguments), you can use something similar:
int itemID = 2; int count = 15; string finalString = itemID.ToString() + ":" + count.ToString();
And to read this case, use the function string.Split (char []);
It will look something like this:
char[] dc = {':'}; string[] decoded = finalString.Split(dc); itemID = int.Parse(decoded[0]); count = int.Parse(decoded[1]);
In general, I am very surprised why so few developers use the ability to write various data in one line, and then decode this line. It's so easy and convenient!
By the way, for those who have not yet had time to join the
NGUI , I
'll give you a couple more useful functions. I had to dig a little in help to find all this and check for performance:
1) Adding an interface element to an existing element (in essence, this is the same as the regular
Instantiate () , but it does not work adequately in NGUI):
NGUITools.AddChild(parent, prefab);
2) When working with grids of elements, it is recommended to use such an entry instead of the usual Destroy (object):
NGUITools.Destroy(object);
3) To add a new function to the list of Callback functions for the button, use the following:
GetComponent<UIButton>().onClick.Add(new EventDelegate()); GetComponent<UIButton>().onClick[GetComponent<UIButton>().onClick.Count - 1].Set( MonoBehaviour, "FunctionName");
4) If you want to change the size of the widget:
NGUIMath.ResizeWidget(widget, widget.pivot, x, y, minWidth, minHeight);
In general, most of the knowledge for working with
NGUI is almost
unnecessary . At least, I manage my tasks quite easily. Be sure to look and the
lesson from the author , where he tells how to create interface elements.
Remember how I complained in the first part about the long work with the interface? Now it takes hours. This is really convenient, and I recommend that all beginner developers take a closer look at this technology, and not torture your brain with a standard interface. Do not repeat my mistakes.
At the moment I have almost finished work on the interface and the core of the game. After that, I will work a little on the game objects and take care of the network game. I already have a few thoughts about this, and what to write in the next part concerning the network game and protection from dishonest players.
And maybe next time I'll tell you about
Steamworks , if I get the
green light on the greenlight .
