Class BoundsField
A UI component for editing 3D bounds with center and size values.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class BoundsField : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Bounds>, IValidatableElement<Bounds>, ISizeableElement, INotifyValueChanging<Bounds>, INotifyValueChanged<Bounds>
Remarks
The BoundsField is a specialized input component that allows users to edit 3D bounds by specifying both the center point and size dimensions. It provides a structured interface with separate numerical fields for each coordinate (X, Y, Z) of both the center position and size values.
This component is particularly useful when working with 3D spaces and requiring precise control over boundary definitions, such as in level editors, collision detection setup, or camera framing configurations.
The field is composed of two main sections:
- Center: Three numerical fields for setting the X, Y, and Z coordinates of the bounds center point
- Size: Three numerical fields for defining the width (X), height (Y), and depth (Z) dimensions of the bounds
Examples
Basic usage of BoundsField in UXML: creating a medium-sized BoundsField in UXML.
<ui:BoundsField name="myBounds" size="M" />
Creating and configuring BoundsField in C#: complete example showing creation, configuration, validation, and change handling.
var boundsField = new BoundsField();
boundsField.size = Size.M;
boundsField.value = new Bounds(Vector3.zero, new Vector3(1, 1, 1));
boundsField.validateValue = (bounds) => bounds.size.x > 0 && bounds.size.y > 0 && bounds.size.z > 0;
// Register for value changes
boundsField.RegisterValueChangedCallback(evt => {
Debug.Log($"New bounds: Center=, Size=");
});
Using BoundsField with validation for game object bounds: example showing how to use BoundsField to edit game object bounds with size validation.
var boundsField = new BoundsField();
// Set up validation for minimum size
boundsField.validateValue = (bounds) => {
var minSize = 0.1f;
return bounds.size.x >= minSize &&
bounds.size.y >= minSize &&
bounds.size.z >= minSize;
};
// Update game object bounds when value changes
boundsField.RegisterValueChangedCallback(evt => {
if (!boundsField.invalid) {
gameObject.transform.position = evt.newValue.center;
// Assuming a cube mesh
gameObject.transform.localScale = evt.newValue.size;
}
});
Constructors
BoundsField()
Default constructor.
Declaration
public BoundsField()
Fields
labelUssClassName
The BoundsField Label styling class.
Declaration
public const string labelUssClassName = "appui-boundsfield__label"
Field Value
| Type | Description |
|---|---|
| string |
rowUssClassName
The BoundsField row styling class.
Declaration
public const string rowUssClassName = "appui-boundsfield__row"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The BoundsField size styling class.
Declaration
public const string sizeUssClassName = "appui-boundsfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
sxFieldUssClassName
The BoundsField X NumericalField styling class.
Declaration
public const string sxFieldUssClassName = "appui-boundsfield__sx-field"
Field Value
| Type | Description |
|---|---|
| string |
syFieldUssClassName
The BoundsField Y NumericalField styling class.
Declaration
public const string syFieldUssClassName = "appui-boundsfield__sy-field"
Field Value
| Type | Description |
|---|---|
| string |
szFieldUssClassName
The BoundsField Z NumericalField styling class.
Declaration
public const string szFieldUssClassName = "appui-boundsfield__sz-field"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The BoundsField main styling class.
Declaration
public const string ussClassName = "appui-boundsfield"
Field Value
| Type | Description |
|---|---|
| string |
xFieldUssClassName
The BoundsField X NumericalField styling class.
Declaration
public const string xFieldUssClassName = "appui-boundsfield__x-field"
Field Value
| Type | Description |
|---|---|
| string |
yFieldUssClassName
The BoundsField Y NumericalField styling class.
Declaration
public const string yFieldUssClassName = "appui-boundsfield__y-field"
Field Value
| Type | Description |
|---|---|
| string |
zFieldUssClassName
The BoundsField Z NumericalField styling class.
Declaration
public const string zFieldUssClassName = "appui-boundsfield__z-field"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the BoundsField. Always null.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
invalid
Set the validation state of the BoundsField.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The BoundsField size.
Declaration
[CreateProperty]
[UxmlAttribute]
[Header("Bounds Field")]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The validation function of the BoundsField.
Declaration
[CreateProperty]
public Func<Bounds, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Bounds, bool> |
value
The value of the BoundsField.
Declaration
[CreateProperty]
[UxmlAttribute]
public Bounds value { get; set; }
Property Value
| Type | Description |
|---|---|
| Bounds |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(Bounds)
Sets the value of the BoundsField without notifying the value changed callback.
Declaration
public void SetValueWithoutNotify(Bounds newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Bounds | newValue | The new value of the BoundsField. |