ドキュメント

Unity Engine

Download Unity

Unity Engine

UxmlAttributeFieldDecorator

An Editor-only container that adds override indicators, binding affordances, and a context menu to any IBindable field.
読み終わるまでの所要時間 2 分最終更新 10日前

A
UxmlAttributeFieldDecorator
is an Editor-only container that wraps any
IBindable
field and adds the visual affordances required for editing UXML attributes: an override indicator bar, binding state indicators, and a context menu with override and binding actions.
Use
UxmlAttributeFieldDecorator
when you want to use a standard field type such as
TextField
or
IntegerField
inside a custom
UxmlSerializedDataPropertyDrawer
, but still want the field to participate in the override and binding system.

Visual states

The decorator changes its appearance to reflect the current state of the attribute it wraps.

UxmlAttributeFieldDecorator in four states: default, override, data binding resolved, and data binding unresolved

State

Visual indicator

DefaultNo indicator. The field shows the inherited or default attribute value.
OverrideA colored bar appears on the left edge, indicating the value is set inline or as a template override.
Data binding resolvedA binding indicator replaces the override bar, showing the attribute is driven by a successfully resolved data binding.
Data binding unresolvedA binding indicator is shown in a distinct style, indicating the data binding could not be resolved.
Right-clicking the decorator opens a context menu with actions appropriate to the current state.

The UxmlAttributeFieldDecorator context menu showing Add Binding, Unset, and Unset all options

Menu item

When available

Description

Add BindingNo bindingOpens the binding editor to create a data binding for this attribute.
Edit BindingBinding presentOpens the binding editor to modify the existing binding.
Remove BindingBinding presentRemoves the data binding from this attribute.
UnsetValue overriddenResets this attribute to its default value.
Unset allAny override presentResets all overridden attributes on this element to their default values.

Create a UxmlAttributeFieldDecorator

You can create a
UxmlAttributeFieldDecorator
in C# or UXML. It can contain multiple child elements, but only its first
IBindable
direct child is bound. The decorator automatically detects that child's binding path when it binds to a
SerializedProperty
.

Create with C#

using Unity.UIToolkit.Editor;using UnityEditor;using UnityEngine.UIElements;// Inside a UxmlSerializedDataPropertyDrawer override:protected override void CreateChildPropertyGUI(VisualElement container, SerializedProperty property, SerializedProperty childProperty){ var decorator = new UxmlAttributeFieldDecorator(); var textField = new TextField(childProperty.displayName) { bindingPath = childProperty.propertyPath }; decorator.Add(textField); container.Add(decorator);}

Create with UXML

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uitke="Unity.UIToolkit.Editor"> <uitke:UxmlAttributeFieldDecorator> <ui:TextField binding-path="label" label="Label" /> </uitke:UxmlAttributeFieldDecorator></ui:UXML>

C# base class and namespace

Namespace:
Unity.UIToolkit.Editor
Base class:
VisualElement

Member UXML attributes

This element has no member UXML attributes of its own. Add any
IBindable
child element to wrap it with override and binding affordances.

Inherited UXML attributes

This element inherits UXML attributes from
VisualElement
.

USS classes

C# property

USS selector

Description

ussClassName
.unity-uxml-attribute-field-decorator
USS class name applied to every
UxmlAttributeFieldDecorator
instance.
-
.unity-uxml-attribute-field-decorator__content-container
USS class applied to the inner content container that holds the wrapped field.
-
.unity-uxml-attribute-field-decorator__affordance-element
USS class applied to the affordance element that displays override and binding indicators.
You can also use the Matching Selectors section in the Inspector or the UI Toolkit Debugger to see which USS selectors affect the components of the
VisualElement
at every level of its hierarchy.

Additional resources