UI

“Where is the play button? What Play But– Oh no we forgot to implement the UI!!!”

UI Architecture: Element Based System

In an object based ui system, collections of UI elements are placed inside of game objects. For example all ui elements in the main menu are children MainMenu GameObject, and all ui elements in the options menu are children of the OptionsMenu GameObject. This makes it fairly easy to swap between menus by setting all ui parent objects inactive then setting the parent object of interest active. Additionally you can set multiple ui objects active if you want to have multiple ui objects active at the same time like a pause menu overlaying the in game UI.

Example

Click to download UIManagementExample.unitypackage.

UI Organization Through Prefab Variants

When crafting the UI for your game, you may find yourself deciding on changing the way certain buttons appear / behave. You may have prefabs for each of these button types but what if you wanted to change the font style for all buttons? You would have to go into each of the button prefabs and update the font used. But what if there was a better way?

Start using prefab variants. You could start with a base button class and create many child prefabs from that base class. Then if you wanted to change the font, you could simply adjust the font in the base prefab and watch it spread to all children prefabs.

The below example showcases a standard menu created from prefabs and prefab variants making it very easy to modify.

Example

Important

This example requires the following packages to be installed:

  • TextMeshPro Essentials

Warning

This example also includes the following packages:

Click to download UIPrefabVariantSystemExample.unitypackage.