Class Vector4Field
A field control that allows users to edit a Vector4 value by inputting its X, Y, Z and W components.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Vector4Field : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Vector4>, IValidatableElement<Vector4>, ISizeableElement, INotifyValueChanging<Vector4>, INotifyValueChanged<Vector4>, IFormattable<float>
Remarks
The Vector4Field is a specialized input control that allows users to edit a Vector4 value through four separate numerical fields representing its X, Y, Z and W components. It's particularly useful for handling 4D vectors or when you need to input quaternion values.
The field is organized in a 2x2 grid layout with clearly labeled inputs for each component. Each component field supports numerical input with floating-point precision and can be individually edited.
Key features:
- Individual floating-point input fields for X, Y, Z, and W components
- Support for value validation
- Customizable number formatting
- Different size variants
- Support for UXML integration
Examples
Basic usage with UXML. Basic UXML declaration of a Vector4Field.
<ui:Vector4Field name="myVector4Field"
size="M"
value="1 2 3 4"
format-string="F2" />
Code example showing various features. Creating and configuring a Vector4Field in code.
var vector4Field = new Vector4Field {
value = new Vector4(1, 2, 3, 4),
size = Size.M,
formatString = "F2",
validateValue = (v) => v.magnitude <= 1.0f
};
vector4Field.RegisterValueChangedCallback(evt => {
Debug.Log($"New value: ");
});
container.Add(vector4Field);
Using with validation and custom formatting. Advanced setup with custom formatting and validation.
var vector4Field = new Vector4Field();
// Custom format function
vector4Field.formatFunction = (float value) => $"{value:0.##}u";
// Validation function
vector4Field.validateValue = (Vector4 v) => {
return v.x >= 0 && v.y >= 0 && v.z >= 0 && v.w >= 0;
};
// Register change callback
vector4Field.RegisterValueChangedCallback(evt => {
if (!vector4Field.invalid) {
ApplyVector4Value(evt.newValue);
}
});
Constructors
Vector4Field()
Default constructor.
Declaration
public Vector4Field()
Fields
rowUssClassName
The Vector4Field row styling class.
Declaration
public const string rowUssClassName = "appui-vector4field__row"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Vector4Field size styling class.
Declaration
public const string sizeUssClassName = "appui-vector4field--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Vector4Field main styling class.
Declaration
public const string ussClassName = "appui-vector4field"
Field Value
| Type | Description |
|---|---|
| string |
wFieldUssClassName
The Vector4Field W NumericalField styling class.
Declaration
public const string wFieldUssClassName = "appui-vector4field__w-field"
Field Value
| Type | Description |
|---|---|
| string |
xFieldUssClassName
The Vector4Field X NumericalField styling class.
Declaration
public const string xFieldUssClassName = "appui-vector4field__x-field"
Field Value
| Type | Description |
|---|---|
| string |
yFieldUssClassName
The Vector4Field Y NumericalField styling class.
Declaration
public const string yFieldUssClassName = "appui-vector4field__y-field"
Field Value
| Type | Description |
|---|---|
| string |
zFieldUssClassName
The Vector4Field Z NumericalField styling class.
Declaration
public const string zFieldUssClassName = "appui-vector4field__z-field"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the Vector4Field.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
formatFunction
The format function of the element.
Declaration
[CreateProperty]
public FormatFunction<float> formatFunction { get; set; }
Property Value
| Type | Description |
|---|---|
| FormatFunction<float> |
formatString
The format string of the element.
Declaration
[CreateProperty]
[UxmlAttribute]
public string formatString { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
invalid
The invalid state of the Vector4Field.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the Vector4Field.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The validation function of the Vector4Field.
Declaration
[CreateProperty]
public Func<Vector4, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Vector4, bool> |
value
The value of the Vector4Field.
Declaration
[CreateProperty]
[UxmlAttribute]
public Vector4 value { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(Vector4)
Set the value of the Vector4Field without notifying the change.
Declaration
public void SetValueWithoutNotify(Vector4 newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | newValue | The new value of the Vector4Field. |