GUI vs. GUILayout

GUI is the bane of Unity Developers

The GUI class in Unity really needs to be removed. Why? Because it gives people a false sense of control. It also creates terrible, terrible practices among Unity Developers. The GUI class allows you to define exact coordinates for your GUI. What you don’t realize, is that this breaks 2 things:

  1. Semantics!

    Your GUI should always be as purely semantic as possible. It is the HTML fight but in Unity. In HTML, using Tables is a deprecated way of styling your websites. It is far superior to use CSS. An HTML website should be purely semantic, and have no styling without CSS. It is the same with GUI’s in Unity. GUISkin’s allow you to skin your GUI’s similarly like CSS for HTML. It can allow you to build far superior GUI’s, as you can easily change out the style whenever needed.

  2. GUISKINS

    GUISkins don’t work properly if you manually place objects. They get really confused when you try and add margins and spacing, change font sizes, etc.

GUILayout is the saviour of Unity Developers

With GUILayout, your GUI is almost entirely semantic in meaning besides the little bit of styling that is required in GUILayout. It also makes GUISkins work properly, and scale and texture things appropriately. If your designer came in, and wanted to completely redesign your interface, with GUILayout, he doesn’t have to touch the code almost at all. The only code he’d have to touch is if he wanted to change the order of things (Button 1 on the right rather than the left, things like this). GUILayout allows your designer to bring in tons of artwork, and easily redo spacing, change out fonts, tweak alignments, etc. without having to go into code at all. This is what is desired, and if you are smart about making your GUI’s, you’d go the GUILayout approach.

“What about awkwardly shaped GUI’s?”

That is something I was hoping you’d ask.

Awkwardly shaped GUI’s are entirely possible using GUILayout.Area(Rect position) and GUI.Window() and GUILayout.FlexibleSpace() and GUILayout.Space(float amt). There will be your 4 best friends when working in weirdly shaped GUI’s. For instance, let’s say you wanted to make a U shaped GUI, you would then make an GUILayout.Area in the area that you want it, and put whatever you need on the left side, flexible space, and then do the right side, then in your second GUILayout.BeginHorizontal() you will do your next row or your bottom row, where it is the bottom of the U.

Conclusion

As you can see, GUILayout is very powerful, and is the superior choice. That is why they added it after all…

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: