Derive from this class to add custom UI to the view generated for a specific ConditionView<T0>.Condition type in the transition inspector.
A VisualElement row is built for every ConditionView<T0>.Condition that
appears in a transition's condition list. A ConditionView<T0> lets you inject custom UI into that
row. Subclasses are discovered by their type parameter: for a ConditionView<T0>.Condition of type T, the
concrete ConditionView<T0> whose type argument matches is used, walking up the
ConditionView<T0>.Condition inheritance chain if there is no exact match.
The ConditionView<T0>.Condition instance is available through ConditionView<T0>.Condition once the view is constructed.
To add custom UI next to the built-in condition UI, override ConditionView<T0>.OnViewBuilt and add
your custom UI to IConditionView.Root.
Do not remove or reparent the built-in elements. Use instead the relevant display toggle.
ConditionView<T0>.DisplayValueFieldConditionView<T0>.DisplayTitleLabelCondition<T0>.DisplayComparisonDropdownImportant: allocate custom UI in ConditionView<T0>.OnViewBuilt. Do not allocate UI in
ConditionView<T0>.OnViewAttached: that callback can fire multiple times during the view's lifetime, and any UI
you allocate there accumulates as duplicates. Instances of this class are created with the row and are never
serialized; do not store state in them that must outlive the view.
Exceptions thrown by the view's constructor or callbacks are logged and do not break the inspector: the
condition row still renders its built-in UI.
// The Condition type that this view customizes. [Serializable] public class Health : Condition<float> { protected override string Title => "Health"; }
// This view is constructed for every Health condition row in the transition inspector. class HealthConditionView : ConditionView<Health> { // Replace the built-in value field with the controls built in OnViewBuilt. protected override bool DisplayValueField => false;
public override void OnViewBuilt() { // Allocate custom UI once, after the built-in UI is ready. var slider = new Slider(0f, 100f) { value = Condition.Value }; slider.RegisterValueChangedCallback(evt => { // Record the write so it is undoable and marks the asset dirty. var stateMachine = Condition.StateMachine; stateMachine.UndoBeginRecordStateMachine("Change health threshold", Condition); Condition.Value = evt.newValue; stateMachine.UndoEndRecordStateMachine(); });
// Style custom UI with USS: load a stylesheet onto the row's content container... View.Root.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/HealthCondition.uss")); // ...and tag elements with classes for it to match. slider.AddToClassList("health-condition__slider");
View.Root.Add(slider); } }
| Property | Description |
|---|---|
| Condition | The ConditionView<T0>.Condition instance this view customizes. |
| DisplayTitleLabel | Whether the built-in title label is displayed. |
| DisplayValueField | Whether the built-in field for the condition's value is displayed. |
| View | The generated view for this condition. Add custom UI to IConditionView.Root. |
| Method | Description |
|---|---|
| OnViewAttached | Called when the condition's row is attached to a UI panel. |
| OnViewBuilt | Called once, after the condition's built-in UI is fully constructed. |
| OnViewDetached | Called when the condition's row is detached from its UI panel. |