Initial Setup
Every UI Document component references a UI Document asset (.uxml
file) that defines the UI and a Panel Settings asset that renders it. You can connect more than one UI Document asset to a single Panel Settings asset.
Right-click Project window, and then select Create > UI Toolkit > UI Document
- In the Hierarchy right click the Scene, select GameObject > UI Toolkit > UI Document. This creates the following:
- A UI Toolkit folder with a Panel Settings asset and a default runtime theme.
- A GameObject with a UI Document component which in turn the is connected to the Panel Settings asset.
- In the Hierarchy select the UIDocument then drag SimpleRuntimeUI.uxml from your Project window to the inspector (Source Asset)
- Create a companion script that derives from
MonoBehaviour
. - Add SimpleRuntimeUI.cs as a component of the UIDocument GameObject.
- Click on the PanelSettings object Project > Assets > UI Toolkit then drag the theme style sheet (.tss) to the Panel.
- Use the Package Manager to install the Input System package.
- Select Edit > Project Settings > Player.
- Set Active Input Handling to Input System Package (New).
- Select GameObject > UI > Event System. This adds an Event System GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary that includes a Standalone Input Module in the Scene. The module shows an error message along with a button in the Inspector window.
Custom USS
- Right click Project → Create → UI Toolkit → Style Sheet
- Add style sheet to umxl view
- Add a Style tag with src attribute pointing to the style sheet
- In the UI Builder upper left corner (+▼) → Add Existing USS
External Links
https://docs.unity3d.com/2022.2/Documentation/Manual/UIToolkits.html
https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-get-started-with-runtime-ui.html
https://docs.unity3d.com/ScriptReference/UIElements.VisualElement.html
https://docs.unity3d.com/Manual/UIE-USS.html
https://docs.unity3d.com/Manual/UIE-create-tabbed-menu-for-runtime.html