Class Vector2IntField
A field control that allows users to input or modify a 2D vector with integer components.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Vector2IntField : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Vector2Int>, IValidatableElement<Vector2Int>, ISizeableElement, INotifyValueChanging<Vector2Int>, INotifyValueChanged<Vector2Int>, IFormattable<int>
Remarks
The Vector2IntField is a specialized input control that enables users to edit two-dimensional vectors with integer components (X and Y values). It provides a clean and intuitive interface for manipulating 2D coordinates, dimensions, or any other data that can be represented as a pair of integer values.
The field consists of two numerical inputs arranged horizontally - one for the X component and one for the Y component. Each component is clearly labeled and can be modified independently.
This component is particularly useful in scenarios involving:
- 2D grid positions or coordinates
- Pixel dimensions or offsets
- Integer-based 2D transformations
Both input fields support keyboard navigation, direct numerical input, and validation to ensure only valid integer values are accepted.
Examples
Basic Vector2IntField Usage:
Creating a basic Vector2IntField in UXML.
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:appui="Unity.AppUI.UI">
<appui:Vector2IntField
name="positionField"
size="M"
value="0,0"
/>
</ui:UXML>
Vector2IntField with Validation:
Setting up a Vector2IntField with validation and change handling.
var vector2IntField = new Vector2IntField();
// Set up validation for positive values only
vector2IntField.validateValue = (v) => v.x >= 0 && v.y >= 0;
// Add change handler
vector2IntField.RegisterValueChangedCallback(evt => {
Debug.Log($"Vector changed to: (, )");
});
Customized Vector2IntField:
Creating a customized Vector2IntField for screen resolution input.
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:appui="Unity.AppUI.UI">
<appui:Vector2IntField
name="resolutionField"
size="L"
value="1920,1080"
format-string="D4"
/>
</ui:UXML>
Constructors
Vector2IntField()
Default constructor.
Declaration
public Vector2IntField()
Fields
containerUssClassName
The Vector2Field container styling class.
Declaration
public const string containerUssClassName = "appui-vector2field__container"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Vector2Field size styling class.
Declaration
public const string sizeUssClassName = "appui-vector2field--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Vector2Field main styling class.
Declaration
public const string ussClassName = "appui-vector2field"
Field Value
| Type | Description |
|---|---|
| string |
xFieldUssClassName
The Vector2Field X NumericalField styling class.
Declaration
public const string xFieldUssClassName = "appui-vector2field__x-field"
Field Value
| Type | Description |
|---|---|
| string |
yFieldUssClassName
The Vector2Field Y NumericalField styling class.
Declaration
public const string yFieldUssClassName = "appui-vector2field__y-field"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the Vector2IntField.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
formatFunction
The format function of the element.
Declaration
[CreateProperty]
public FormatFunction<int> formatFunction { get; set; }
Property Value
| Type | Description |
|---|---|
| FormatFunction<int> |
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 Vector2IntField.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the Vector2IntField.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The validation function to use to validate the value.
Declaration
[CreateProperty]
public Func<Vector2Int, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Vector2Int, bool> |
value
The value of the Vector2IntField.
Declaration
[CreateProperty]
[UxmlAttribute]
public Vector2Int value { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2Int |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(Vector2Int)
Set the value of the Vector2IntField without notifying the change.
Declaration
public void SetValueWithoutNotify(Vector2Int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2Int | newValue | The new value of the Vector2IntField. |