Get started with in-scene UI authoring
Create a UI layout using the in-scene UI authoring workflow, following a step-by-step example.
読み終わるまでの所要時間 4 分最終更新 20日前
This example shows how to create UI with in-scene UI authoring. It follows the same workflow as Get started with UI Builder, but uses in-scene UI authoring instead.
Prerequisites
Before you start, familiarize yourself with the following:
- Introduction to visual elements and visual tree
- Introduction to UXML
- Introduction to USS
- UI authoring interface
Example overview
This example creates the same character selection screen as Get started with UI Builder, using in-scene UI authoring instead.
Create the root element
Create a root visual element that covers the entire screen. Set your root element to have a background color and center all child elements in the middle of the screen.
To create the root element:
-
Create a project in Unity with any template.
-
Create a Panel Renderer and a UXML Document named as. For instructions, refer to Create a Panel Renderer and a UXML Document.
MainView.uxml -
In the Hierarchy window, select the arrow icon (>) next toto enter the UI Staging mode.
MainView.uxml -
In the UI Staging mode, right-click anywhere in the Hierarchy window, and select UI Toolkit > Standard Elements >to add a visual Element as the root element.Visual Element
?

Create new elements with in-scene UI authoring
Create the parent container
Create a new visual element underneath the root element. This element becomes the parent container for the left and right sections of the UI.
To create the parent container:
- Right-click the visual element you just created in the Hierarchy window. Select Standard Elements > Visual Element to add a child visual element.
Create the character names list container
Add a list view as the child element of the container to hold the character names.
To create the character names list container:
-
Select the visual element you just created and select Standard Elements > UI Library.
-
Under Containers, drag List View to the container visual element in the Hierarchy window.
-
Select the element from the Hierarchy window.
-
In thewindow, set its name toInspector
?
.CharacterList
Background container with the empty element inside
Create the character details container
Add a new visual element under the same parent as the to hold the character details container. The purpose is that when the user selects a character from the list on the left, it displays the character's portrait, name, and class.
#CharacterListTo create the character details container:
- Right-click the parent container visual element in the Hierarchy window. Select Standard Elements > Visual Element.
Create a USS class for the border style
The character details container uses the same border styles as the character names list container. Create a USS class to apply to both containers.
To create a USS class for the border style:
- Select Window > UI Toolkit > Style Sheets to open the Style Sheets window.
Create the character portrait background
Add the individual UI controls to the character details container. The first step is to add the character portrait background.
To create the character portrait background:
- Add a visual element to the child of the character details container.
Create labels
Add two label controls to the character details container to display the selected character's name and class.
To create labels:
-
Right-click the parent of the visual element you just created in the Hierarchy window and select Standard Elements > Label.
-
Set its name to.
CharacterName -
Create another Label from the character details container in the Hierarchy window.
-
Set its name to.
CharacterClass
Add labels for name and class
-
Select theelement.
#CharacterName -
Set Text > Font Style to.
B -
Set Text > Size topixels.
18 -
Select File > Save to save the changes to.
MainView.uxml
Extract inline styles
In the in-scene UI authoring, you can create elements and use inline styles only to experiment while the number of elements is still small. As you build a more complex UI, it's easier to manage styles using style sheets. You can extract inline styles to a style sheet in in-scene UI authoring.
To extract inline styles to a style sheet:
- Select the root visual element.
- Select File > Save.
If you want to continue to work on the Create a list view runtime UI example, you can repeat the steps to extract styles for all the other elements, and follow the instructions to create the example.