What is Better UI?
Better UI extends the Unity UI system (uGUI) to make it better. It solves common problems with uGUI like fixed sizes instead of relative sizes (e.g. font size) or allowing to have more than one transition (with additional transition types).
It also comes with two editor windows making it much easier to design your UI for different resolutions. The first editor window allows it to switch the game view resolution with a list of buttons (much faster workflow than with the built in dropdown); the other editor window can snap the anchors of the selected object(s) to its borders or a certain point to convert the positioning from pixel sized to relative sizes on the screen.
Can I use Better UI in my existing uGUI project?
Yes! Better UI has all the Controls of uGUI (Button, Text, Toggle, âŚ). But they are not completely new controls. Instead they extend the uGUI Controls by further functionality.
So if you need a Better UI feature on one of your controls, just right-click on that controls component and select âMake it Betterâ. This will exchange the Control with its âBetterâ pendant. All the variables will stay and also all references to that object are kept.
This allows a very comfortable workflow: Build everything with uGUI as usual and make just those controls âBetterâ where you need the extra functionality.
What are the most exciting Features?
- Resolution Dependent Sizing
Layout Groups (Horizontal / Vertical / Grid) and some other components with size-related variables are using Sizer objects to define the size-scaling on different resolutions. You need an optimized resolution to work with as a reference. Then you can decide for each sizer value if it should scale relative to the change of the screen width, height, aspect ratio, DPI or a mixture of them and how much impact they have. This allows to have a similar visual appearance on any resolution.
The Resolution Monitor keeps track of resolution changes and informs all resolution-dependent objects in case of a change (to recalculate the sizes).
This feature can also be activated during runtime with one line of code: IngameResolutionMonitor.Create();
- Responsive Design
You can define which kinds of screens you would like to have differences in the UI for. For example, you can have differences for Landscape and Portrait mode, for different Screen Sizes or aspect ratios or special features (like touch screen) or a combination of these.
For each of them you can have different positions / anchors / pivots of your UI elements. But also many settings can be set differently, like the orientation of a layout group (switch between horizontal and vertical). Additionally you can show or hide elements for certain configurations.
Donât worry: You will not need to specify everything for every screen configuration. A smart fallback logic will use the right configuration if the current screen was not specified for an element.
- Transitions
Selectables and all derivations of it (like Buttons) can have one Transition by default (Normal, Hover, Pressed and Disabled states). With Better UI you can add any number of additional transition to one selectable (e.g. The background Image as well as the Text color should change? Not possible without scripting in uGUI â no problem with Better UI).
Better UI provides the same Transition types as uGUI:
- Color Tint / Color32 Tint: Changes the color of the target graphic
- Sprite Swap: Exchanges the sprite of the target image
- Animation: Triggers animations on itself (in Better UI you have to specify a target animator)
Better UI also allows additional transition types:
- Object Activeness: Setting target Game Object active or inactive
- Alpha: Changes the transparency of target graphic (very much like Color Tint but keeps the current color)
- Material Property: Changes a property of a material which comes with Better UI or which uses the same approach and has an entry in the Material Scriptable Object. (The approach is to store the variables inside the vertex information for ease of use and better performance)
Toggles also have additional transitions for the toggle states (on / off). It uses the same system as ânormalâ transitions so all the transition types are also available for toggle transitions.
Do you need tabs? No problem: Just create some Toggles, make them Better and assign them to a Toggle group. Add a Toggle Transition to each of them with âObject Activenessâ as Transition Type and assign the contents of the tab-pages. Done.
- Better Image
Slicing
There are additional options for sliced and tiled images.
A sliced image have the option âKeep Border Aspectâ. This will scale the borders when uGUI would normally shrink or stretch them if it doesnât fit inside its bounds properly anymore (which can easily happen with different resolutions).
It is also possible to scale the border making it smaller or bigger than in the source image. The scaling can be connected to the resolution (as explained above).
The scale can also be used in tiled mode. Because of the connection to the resolution you can define the number of tiles by scaling (e.g. to have a background with 10 Stripes) and on other resolutions the tiling will be the same (so that there are always 10 Stripes on any resolution).
Colors and Materials
An Image can have a color but also can have a horizontal or vertical gradient for no extra performance cost.
Images also have predefined Materials (Standard, Grayscale, Hue-Saturation-Brightness, Color Overlay). The Material properties can changed inside the image inspector to e.g. shift the colors. All images can share the same material while having different property values, which is good for performance if you use it on multiple images.
All predefined Materials come with several blending effects (Normal, Additive, Color Dodge, Multiply) which allows to mix the colors of the image with the background.
Own materials still can be assigned. There is also an option to clone the assigned material for the selected image to change some properties only for that image.
- Better Text
The Font Size is scaled with a sizer as described above.
But there are also three available Fitting Modes:
- Sizer Only: Just uses the sizer to affect the font size. Doesnât care about text overflow.
- Stay In Bounds: Uses the sizer as long as the text fits inside the bounds. Shrinks the font size if it doesnât fit anymore.
- Best Fit: Like in uGUI â adjusts the font size to fill up as much as possible of the bounds.
The Stay In Bounds option will be chosen as default when making a text better.
This makes sense: normally designers want to have the same size on all Buttons. But if the Text is too large it is okay to shrink it. Designers normally donât like best fit option because the font size would be different on almost every button.
These options also work with Better TextMeshPro UI! (Note: âBetter TextMesh Proâ is not included, but can be downloaded for free here)
- Helpful Tools
There are three tools coming with Better UI:
- Snap Anchors: Can set the anchors of one or more UI elements to their borders or to a certain point with just a click. This converts the positions to relative coordinates, so that they are at the same relative location when changing resolution
- Align / Distribute: Allows you to easily position a list of elements nicely. You can align them, so that they touch to the same horizontal or vertical line. You also can distribute them so that the distance between them is the same.
- Pick Resolution: Instead of using the resolution drop down of the game view this tool can show you all resolutions on small buttons. That gives a better overview and makes it faster to switch between resolutions. You also can apply filters for resolutions and change the layout of the window and its content.
Additionally, you can simulate your specified screen configurations with it to easily test your responsive designs.
Does it work properly?
We (Thera Bytes GmbH) use it in our projects and it is a great time saver. We are not aware of any major issues, so I guess it is (almost?) bug-free. However, if you find a bug, please report it in this thread. Full source code is provided, so, any fixes posted here can be easily applied by yourself if you donât want to wait for the next version.
If you want to know more about how to work with better UI you may watch my explanation videos:
Links
Better UI @ Asset Store: Better UI | GUI Tools | Unity Asset Store
Online Documentation: General
Thera Bytes Website (German): http://therabytes.de/