PropertyContainer Class

Description

Element that shows a SerializedProperty's prefab override indicators, and the property's menu on context click. UXML support

public class PropertyContainer : VisualElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle
Inheritance
Remarks

Currently, Unity only adds these capabilities for fields that inherit from BaseField<TValueType> or Foldout. This element makes those features available everywhere. It can be used with any SerializedProperty, even those that have nested properties inside. To use it, assign a bindingPath to the property it represents, and call the Add(VisualElement) method to add the UI for that property.

It should also show other kinds of indicators, like the yellow ones from the localization package, but I haven't tested that.

Examples

The prefabOverrideUssClassName can be used to apply custom styles when theres a prefab override. For example, a custom style sheet could do something like this to make a particular label bold when there's an override:

.editor-aid-property-container--prefab-override .my-custom-label-class {
    -unity-font-style: bold;
}

Constructors

PropertyContainer()

Constructor.

PropertyContainer(String)

Constructor. Receives a string that is assigned to bindingPath.

PropertyContainer(SerializedProperty)

Constructor. The Property parameter just sets the bindingPath; it still needs to be bound.

Fields

contentUssClassName

USS class name for the content element.

prefabOverrideUssClassName

USS class name of elements of this type when their property is a prefab override.

propertyProxyUssClassName

USS class name for an invisible element that makes Unity apply the relevant SerializedProperty features.

ussClassName

USS class name of elements of this type.

Properties

bindingPath

The path to property represented by this element.

Events

onPrefabOverrideChanged

An event that's triggered when a change in the property's override status is detected. Receives a Boolean that indicates whether the property is a prefab override.

Extension Methods

UIToolkitExtensions.GetLocalRect(VisualElement)
UIToolkitExtensions.GetChildren<TElement>(VisualElement, List<TElement>, Func<TElement, Boolean>)
UIToolkitExtensions.GetFirstChild<TElement>(VisualElement, Func<TElement, Boolean>)
UIToolkitExtensions.ForEachChild<TElement>(VisualElement, Action<TElement>)