Class FloatField
A text field that accepts floating-point numeric values.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class FloatField : NumericalField<float>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<float>, IValidatableElement<float>, ISizeableElement, INotifyValueChanging<float>, INotifyValueChanged<float>, IFormattable<float>, IValueField<float>
Remarks
FloatField is an input control that allows users to enter and edit floating-point numbers. It provides validation, formatting, and range constraints for numeric input.
The component supports both keyboard input and increment/decrement functionality. Users can directly type values or use up/down arrow keys to adjust the value incrementally.
Note: The field can be customized with various formatting options and can display optional units alongside the numeric value.
Examples
Basic FloatField with validation.
var field = new FloatField
{
value = 50.0f,
lowValue = 0.0f,
highValue = 100.0f,
formatString = "F1",
unit = "%"
};
// Add validation for even numbers
field.validateValue = (value) => value % 2 == 0;
FloatField with custom formatting and event handling.
var field = new FloatField();
// Custom format function to display with units
field.formatFunction = (value) => $"{value:0.##} sec";
// Listen for value changes
field.RegisterValueChangedCallback(evt =>
{
Debug.Log($"Value changed from to ");
});
UXML Definition Example.
<ui:FloatField
name="opacity-field"
value="0.5"
low-value="0"
high-value="1"
format-string="P0"
unit="opacity"
size="M" />
Constructors
FloatField()
Default constructor.
Declaration
public FloatField()
Methods
ApplyInputDeviceDelta(Vector3, DeltaSpeed, float)
Apply input device delta to the UnityEngine.UIElements.IValueField`1 element.
Declaration
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, float startValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | delta | The delta from the input device. |
| DeltaSpeed | speed | The speed of the delta application. |
| float | startValue | The starting value for the delta application. |
Overrides
AreEqual(float, float)
Check if two values of type TValue are equal.
Declaration
protected override bool AreEqual(float a, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The first value to test. |
| float | b | The second value to test. |
Returns
| Type | Description |
|---|---|
| bool | True if both values are considered equals, false otherwise. |
Overrides
GetIncrementFactor(float)
Calculate the increment factor based on a base value.
Declaration
protected override float GetIncrementFactor(float baseValue)
Parameters
| Type | Name | Description |
|---|---|---|
| float | baseValue | The base value. |
Returns
| Type | Description |
|---|---|
| float | The increment factor. |
Overrides
Increment(float, float)
Increment a given value with a given delta.
Declaration
protected override float Increment(float originalValue, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| float | originalValue | The original value. |
| float | delta | The delta used for increment. |
Returns
| Type | Description |
|---|---|
| float | The incremented value. |
Overrides
Max(float, float)
Return the biggest value between a and b.
Declaration
protected override float Max(float a, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The first value to test. |
| float | b | The second value to test. |
Returns
| Type | Description |
|---|---|
| float | The biggest value. |
Overrides
Min(float, float)
Return the smallest value between a and b.
Declaration
protected override float Min(float a, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The first value to test. |
| float | b | The second value to test. |
Returns
| Type | Description |
|---|---|
| float | The smallest value. |
Overrides
ParseRawValueToString(float)
Define the conversion from a TValue value to a string value.
Declaration
protected override string ParseRawValueToString(float val)
Parameters
| Type | Name | Description |
|---|---|---|
| float | val | The TValue value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
Remarks
This method is used to convert the value to a string without any formatting.
ParseStringToValue(string, out float)
Define the conversion from the string value to a TValue value.
Declaration
protected override bool ParseStringToValue(string strValue, out float val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| float | val | The TValue value returned. |
Returns
| Type | Description |
|---|---|
| bool | True if the conversion is possible, False otherwise. |
Overrides
ParseValueToString(float)
Define the conversion from a TValue value to a string value.
Declaration
protected override string ParseValueToString(float val)
Parameters
| Type | Name | Description |
|---|---|---|
| float | val | The TValue value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |