Class AssetTargetField
A field that displays a reference to an asset and lets the user reassign or clear it.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class AssetTargetField : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<AssetReference>, IValidatableElement<AssetReference>, INotifyValueChanged<AssetReference>, ISizeableElement, IPressable
Remarks
This is the UITK counterpart of BOTH the registry's asset-target-field and its
object-field. The two registry components are the same control — object-field
is asset-target-field without the size prop and without the clear button — so
UITK deliberately ships one class rather than a near-duplicate.
The field renders, left to right: an optional leading type icon, the referenced asset's name (or the empty-state label), a clear button shown only while something is assigned, and a pick button that opens customPicker.
Example
var field = new AssetTargetField
{
type = typeof(Material),
value = new AssetReference { name = "Bronze", type = "Material", typeIcon = "sphere" },
};
field.customPicker = myObjectPickerHost;
UXML
<appui:AssetTargetField size="Md" show-clear-button="true" empty-label="None" />
Constructors
AssetTargetField()
Default constructor.
Declaration
public AssetTargetField()
Fields
clearButtonUssClassName
The AssetTargetField clear button styling class.
Declaration
public const string clearButtonUssClassName = "appui-assettargetfield__clear-button"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The AssetTargetField leading icon styling class.
Declaration
public const string iconUssClassName = "appui-assettargetfield__icon"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The AssetTargetField label styling class.
Declaration
public const string labelUssClassName = "appui-assettargetfield__label"
Field Value
| Type | Description |
|---|---|
| string |
pickButtonUssClassName
The AssetTargetField pick button styling class.
Declaration
public const string pickButtonUssClassName = "appui-assettargetfield__pick-button"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The AssetTargetField size styling class.
Declaration
public const string sizeUssClassName = "appui-assettargetfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The AssetTargetField main styling class.
Declaration
public const string ussClassName = "appui-assettargetfield"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clearButton
The button that clears the reference. Only visible while a value is assigned and showClearButton is true.
Declaration
public IconButton clearButton { get; }
Property Value
| Type | Description |
|---|---|
| IconButton |
clickable
Clickable Manipulator for this AssetTargetField.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
contentContainer
Logical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
customPicker
The picker opened when the field, or its pick button, is pressed.
Declaration
[CreateProperty]
public ICustomAssetTargetFieldPicker customPicker { get; set; }
Property Value
| Type | Description |
|---|---|
| ICustomAssetTargetFieldPicker |
Remarks
Null by default — the field has no way to enumerate assets on its own. Pressing the pick button with no picker assigned raises pickRequested and does nothing else, which is what lets the field ship before a picker host exists.
emptyLabel
The label shown when no asset is assigned.
Declaration
[CreateProperty]
[UxmlAttribute]
public string emptyLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Defaults to None, matching the registry. It is fed through
LocalizedTextElement, so it can be a localization key.
iconElement
The leading type icon.
Declaration
public Icon iconElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
invalid
Whether the current value of the AssetTargetField is valid or not. This is determined by the validateValue function.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
pickButton
The button that opens customPicker.
Declaration
public IconButton pickButton { get; }
Property Value
| Type | Description |
|---|---|
| IconButton |
showClearButton
Whether the clear button is offered at all. When true the button still only shows while a value is assigned, because there is nothing to clear otherwise.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool showClearButton { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the element.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
type
The type of the AssetReference that this field accepts. This is used to filter the assets that can be assigned to this field, and it drives the leading icon when the assigned value carries no typeIcon.
Declaration
[CreateProperty]
public Type type { get; set; }
Property Value
| Type | Description |
|---|---|
| Type |
validateValue
A function that validates the value of the AssetTargetField. It returns true if the value is valid, false otherwise.
Declaration
[CreateProperty]
public Func<AssetReference, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<AssetReference, bool> |
value
The current value of the AssetTargetField.
Declaration
[CreateProperty]
public AssetReference value { get; set; }
Property Value
| Type | Description |
|---|---|
| AssetReference |
Methods
ClearValue()
Clears the assigned reference, as the clear button does.
Declaration
public void ClearValue()
Remarks
Named ClearValue rather than Clear because
Clear() removes every child, so a field held in a
VisualElement variable would tear out its own icon, label and
buttons instead of dropping the reference.
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
OpenPicker()
Opens customPicker, as the pick button does.
Declaration
public void OpenPicker()
SetValueWithoutNotify(AssetReference)
Sets the value of the AssetTargetField without sending a change event.
Declaration
public void SetValueWithoutNotify(AssetReference newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetReference | newValue | The new value to set. |
Events
cleared
Raised when the user clears the reference with the clear button. The registry's
onClear callback. The value change itself is also reported through the usual
ChangeEvent_1.
Declaration
public event Action cleared
Event Type
| Type | Description |
|---|---|
| Action |
pickRequested
Raised when the user asks for the picker, whether or not a customPicker
is assigned. The registry's onPick callback.
Declaration
public event Action pickRequested
Event Type
| Type | Description |
|---|---|
| Action |