Search Unity

UI Toolkit: New and updated demos for programmers and artists

Screenshots from the UI Toolkit Sample – Dragon Crashers – and the QuizU sample projects.
Screenshots from the UI Toolkit Sample – Dragon Crashers – and the QuizU sample projects.
Share

Is this article helpful for you?

Thank you for your feedback!

We’re happy to announce the availability of two new and updated educational samples to support the different perspectives of programmers and artists/designers in creating professional in-game UI with UI Toolkit.

UI Toolkit provides a set of tools for developing performant and scalable runtime UI for games and applications, custom extensions for the Unity Editor, and runtime debugging tools. Its core concepts and workflows will be familiar to you if you have experience developing web pages or applications.

Our aim with these educational samples is to help you build rich, responsive, and scalable UIs with UI Toolkit. The new demo QuizU, for programmers, and the updated UI Toolkit SampleDragon Crashers for artists and designers, are two very different projects, each with extensive supporting instructional content.

An example of a character screen from UI Toolkit Sample – Dragon Crashers shows how the mix of GameObjects and UI Elements makes the screen dynamic and fun to use.
An example of a character screen from UI Toolkit Sample – Dragon Crashers shows how the mix of GameObjects and UI Elements makes the screen dynamic and fun to use.

New: QuizU demo for UI Toolkit

The QuizU project is a UI Toolkit-based game.
The QuizU project is a UI Toolkit-based game.

QuizU is a programmer-centric sample of an interactive quiz application that shows how UI Toolkit components can work together, leveraging various design patterns, in a small but functional game with multiple screens and game flow management.

The demo consists of two parts: 10 small, digestible samples that demonstrate different aspects of UI Toolkit, and a mini quiz game that consolidates many of the techniques from the 10 scenes into a complete project.

The minimalist visual style of the mini-game lets you focus on the mechanics of the UI implementation, without getting lost in the design details.

A playable mini game to demonstrate design patterns

The quiz game illustrates how to use the state pattern for game flow, manage multiple menu screens, use the model-view-presenter pattern, implement event handling in UI Toolkit, and more. The gameplay is a very simple quiz game mechanic but the intent is to show and teach implementation techniques that you can use in your own projects.

Play QuizU to see how design patterns and UI Toolkit can work together.
Play QuizU to see how design patterns and UI Toolkit can work together.

By integrating some of these design patterns consistently into your project, you can improve code readability and make your codebase cleaner. Design patterns not only reduce refactoring and the time spent testing, they can speed up development processes for your entire team.

Additionally, event-driven architecture, whereby game components communicate with each other through events, promotes loose coupling for scalability and testability.

Bite-sized demo scenes

Select a demo from the Demo Selection Screen.
Select a demo from the Demo Selection Screen.

The second part of the demo consists of 10 small demo scenes. Each demo scene represents a specific technique or feature. Consider them as a set of recipes to inspire and guide you as you evaluate UI Toolkit for your next project. Here's a brief sampling of the UI Toolkit features and techniques the demo scenes illustrate:

  • UXML and Visual Trees: UXML files form a hierarchical structure of UI elements. These visual trees serve as a blueprint for your user interface.
  • Flexbox: The Flexible Box Layout Model (Flexbox) provides an efficient layout model for arranging UI elements dynamically within a container.
  • Unity Style Sheets (USS): USS allows developers to customize UI elements with predefined styles. Reskinning your UI is just a matter of swapping style sheets.
  • UQuery: UQuery simplifies the process of searching through a complex hierarchy of UI elements, enabling seamless navigation to specific UI components within the visual tree.
  • Pseudo-classes: Pseudo-classes can be used to create interactive and animated UI elements with minimal extra code, adding extra “juice” to your visual interface (e.g., enlarging a button when hovering over it or changing a text field color after selection).
  • UI Toolkit Event System: UI Toolkit has its own event system, designed to handle your UI's clicks, changes, and pointer input, even across complex hierarchies.
  • Manipulators: Encapsulating related event callbacks into a single class, a manipulator promotes reusability and makes it easier to define user interactions (e.g., a click-and-drag manipulator for an inventory system, a gesture manipulator for a pinch-to-zoom effect, etc.).
  • Custom Controls: The demo shows how to define and instantiate custom VisualElement through UxmlFactory and UxmlTraits classes. These custom controls can then be reused through scripts or the UI Builder.

We recommend that you download QuizU using Unity 2022 LTS. You can also follow along in our series of articles, published on Unity Discussions, that accompany the demo. The articles are here:

Updated: UI Toolkit Sample – Dragon Crashers (2022 LTS)

Updated for Unity 2022 LTS: Responsive UI in landscape and portrait
Updated for Unity 2022 LTS: Responsive UI in landscape and portrait

In September 2022, we launched UI Toolkit Sample – Dragon Crashers (you can read the launch blog post). This demo of a full-featured interface over a slice of the 2D mini RPG project Dragon Crashers, shows you techniques for leveraging UI Toolkit in your own applications. It’s the companion piece to the e-book User interface design and implementation in Unity, also released in late 2022.

You can now download a new version of UI Toolkit Sample – Dragon Crashers for Unity 2022 LTS. The improvements and updates in this latest version include:

  • Support for runtime landscape and portrait screen modes through themes and the GeometryChangedEvent in UI Toolkit
  • Implementation of the SafeArea API to contain UI functionality within the usable screen area of a device
  • Increased fps limit for mobile devices to 60 fps
  • Refactored, simplified selectors and USS stylesheets
  • Higher resolution icons
  • Improved fixed VFX spawning position for different screen ratios and some cursor inconsistencies
  • Refactored design patterns for cleaner UI architecture
  • New learning content provided via the Tutorial Inspector window
The demo is updated with usage of the SafeArea API, which helps you to contain UI functionality within the usable screen area of your device.
The demo is updated with usage of the SafeArea API, which helps you to contain UI functionality within the usable screen area of your device.

A new user guide and video tutorial for the demo

We also added a user guide for the updated project. This is in response to feedback we received from users who asked for better instructional content to help them understand the techniques and features used in the demo.

Finally, a video walkthrough of the project is now available to help you navigate through the demo. Check it out:

This content is hosted by a third party provider that does not allow video views without acceptance of Targeting Cookies. Please set your cookie preferences for Targeting Cookies to yes if you wish to view videos from these providers.

We hope you’ll pick up many useful tips with QuizU and the updated UI Toolkit Sample – Dragon Crashers. You’ll find all of Unity’s advanced e-books for programmers, artists, technical artists, and designers in the Unity best practices hub

Is this article helpful for you?

Thank you for your feedback!

Join a discussion on our Forums
Related Posts