ドキュメント

Unity Engine

Download Unity

Unity Engine

UI authoring interface

Understand the UI authoring interface.
読み終わるまでの所要時間 6 分最終更新 1日前

Understand the windows and panels that make up the UI authoring interface for authoring runtime UI in the scene.
You can edit UXML assets directly from the Hierarchy window in the Main Stage, or open them in UI Staging to edit them in context or in isolation. The UI Library, Inspector, Style Sheets, and UI Viewport windows support layout, styling, and preview while you edit.

UI authoring interface

The UI authoring interface:
A: UI Staging
B: UI Library
C: Inspector
D: Style Sheets
E: UI Viewport
注
In-scene UI authoring is for runtime UI. To create Editor UI, use UI Builder.

Main Stage

In the Main Stage, you can edit any UXML document or template instance directly from the Hierarchy window, without entering staging mode. Changes are written to the source
.uxml
file, so every instance of that asset receives them.
Editing a UXML asset in the Main Stage doesn't mark the scene as modified. The scene is only marked as modified when something in the scene itself changes.
The following table shows where to edit, depending on what you want to change:

Mode

What you see

Use it to

Main StageThe scene, with UXML assets editable in the Hierarchy window.Change a UXML asset and every instance of it.
In contextThe UXML asset in UI Staging, with the scene visible around it.Edit a document with its scene context, for example to override attributes on a template instance inside it.
In isolationThe UXML asset in UI Staging, on its own.Edit a template asset that has overrides applied to its instances.
An instance receives changes made to its UXML asset unless the changed attribute has an override on that instance. For more information, refer to Use UXML instances as templates in-scene.

UI Staging

UI Staging uses the same staging mechanism as in-context prefab editing. When you enter staging mode for a UXML asset, you edit the asset in the context of your scene or in isolation. You don't need to enter staging mode to edit UI, but it lets you focus on one document.
重要
Changes made in staging mode and in the Main Stage are written directly to the UXML asset, not to a scene instance. Edits affect all places the asset is used, except where an instance overrides the changed attribute.
You must enable in-scene UI authoring before you can enter staging mode.
You can enter staging mode in the following ways:
  • In the
    Inspector

    ?

    window, when the UXML is selected, open the More (⋮) menu and select Open in Context.
  • Select the arrow (>) beside the UI element in the Hierarchy window to open it in context.

    Open in context button

    To open it in isolation instead, hold Alt (Windows) or Option (macOS) while selecting the arrow.
  • Right-click a visual element and select Open Asset to open the referenced element in staging mode.
The Inspector window shows the attributes and styles of the selected visual element. The UI Library, Style Sheets, and UI Viewport windows are also available for use while in staging mode.
The Style Sheets and UI Viewport windows follow your selection. When you select a GameObject with a Panel Renderer component, both windows show that UI document and its style sheets, in the Main Stage or in staging mode.

UI Library

The UI Library window (Window > UI Toolkit > UI Library) lets you browse, search, and add visual element controls and UXML files to your UI. You can dock it anywhere in the Editor layout.
The UI Library window includes:
  • Standard runtime UI Toolkit controls
  • UXML files
To add elements, drag them from the UI Library window into the Hierarchy window or UI Viewport window.
If you add an element from the UI Library window when the selection isn't a UI Toolkit element, Unity creates a new GameObject with a Panel Renderer component and a new UXML asset that contains the element.

Inspector for visual elements

The Inspector window displays the attributes and styles of the selected visual element. Select an element in the Hierarchy window, or select it in the
Scene

?

view (world space UI) or UI Viewport window (screen space UI).
The Inspector window supports:
  • Data binding
  • A search field to find style properties quickly. Press Ctrl+F (Windows) or Cmd+F (macOS) to focus the search field. Use the search filters to narrow results by category.
  • A More (⋮) menu in the header with actions for the parent UXML, such as Select in Project or Open in UI Builder.

Style Sheets

The Style Sheets window (Window > UI Toolkit > Style Sheets) manages USS style sheets and style rules for your open UXML file. It provides the same selector list as the Style Sheets pane in UI Builder, as a dockable window. Style rules can target a single selector (such as
.unity-button
) or multiple selectors in one rule (such as
.unity-button, .unity-label
).
When you select a selector, the Inspector window shows the associated style properties.
To apply a style class to a visual element, drag the selector tag from the Style Sheets window onto the element in the Hierarchy window.

UI Viewport

The UI Viewport window (Window > UI Toolkit > UI Viewport) provides the flat 2D canvas view as a dockable window. Use it to:
  • Make pixel-accurate UI edits
  • Preview hover effects, animations, and transitions without entering Play mode
  • Author and edit screen space UI
Selection in the UI Viewport window is synchronized with the Inspector and Hierarchy windows. For World Space UI, use the Scene view and UI Viewport window side by side.
To show or hide the UXML or USS preview, toggle the options in the UI Viewport window's More (⋮) menu.

Screen Space UI and World Space UI

In-scene UI authoring supports both rendering modes. The render mode is set on the Panel Settings asset.
World Space UI exists as a surface in the 3D scene. You can click elements in the Scene view to select them. For more information, refer to World Space UI.
Screen Space UI is composited after the scene and isn't rendered in the 3D Scene view. Use the UI Viewport window as the primary place to view and edit screen space UI.
To find screen space UI in the Scene view, use its UI gizmo icon. The icon appears when you add a UXML Document to the Hierarchy window, and its position follows the GameObject's Transform. Select the icon to select the UI. To show, hide, or customize the icon, use the Gizmos menu in the Scene view toolbar.
When you select screen space UI, the Scene view shows a preview of it in an overlay. For more information, refer to Preview screen space UI in the Scene view.

Additional resources