Version: 2023.2
언어: 한국어
Bindable elements reference
Binding system implementation details

Bindable data types and fields

This following describs the data type conversions and fields supported by PropertyField.

Data type conversions

Most built-in controls in UI Toolkit implement the INotifyValueChanged interface for a specific data type. For example, DoubleField implements INotifyValueChanged<Double>, which means you can bind the DoubleField control to a property of type double. You can bind more data types with the binding system. For example, you can bind a property of type int to a DoubleField.

The following table lists the source and target data types that you can bind:

Source data type Target data type of INotifyValueChanged
long
  • long
  • int
  • string
  • float
int
  • int
  • string
  • float
double
  • double
  • float
float
  • float
  • double
char
  • char
  • string

Note: To prevent data loss, use a PropertyField or use the appropriate data types as shown in the Fields supported by PropertyField table below.

Fields supported by PropertyField

When the Inspector window is populated, if a custom Editor doesn’t exist for a type, the binding system calls InspectorElement.FillDefaultInspector(). This creates a PropertyField for each SerializedProperty on the SerializedObject.

Each PropertyField has a matching control under it, such as an IntegerField to represent an int, or a Toggle to represent a bool. If the property has sub-properties, the PropertyField has a Foldout control. That Foldout has the appropriate default controls under each sub-property. If you created a custom PropertyDrawer for a Property, the visual tree returned from the PropertyDrawer’s CreatePropertyGUI() method is used instead.

참고:

When you create a custom UI, don’t use a PropertyField unless you can’t find a specific control for it. For example, to create a control in your visual tree and bind it to a Color, use a ColorField rather than a PropertyField. This makes visual trees more lightweight and operations faster.

The use of PropertyField incurs additional overhead because it resolves the concrete field to use after binding. This extra step can affect performance. However, PropertyField is beneficial for some uses. For example, it supports custom drawers, which you can use to handle specific properties in a personalized way. This eliminates the need to guess the field type for drawing, which can reduce errors.

The following table lists fields supported by PropertyField and their data type:

필드 데이터 타입
BoundsField Bounds
BoundsIntField BoundsInt
ColorField 색상
CurveField AnimationCurve
FloatField float
GradientField 그레디언트
Hash128Field Hash128
IntegerField int
IntegerField int, for the ArraySize
LayerMaskField unit
LongField long
ObjectField UnityEngine.Object
PopupField<string> 열거형
RectField Rect
RectIntField RectInt
TextField 문자열
TextField, with a maxLength=1 char
Toggle bool
Vector2Field Vector2
Vector2IntField Vector2Int
Vector3Field Vector3
Vector3IntField Vector3Int
Vector4Field Vector4

추가 리소스

Bindable elements reference
Binding system implementation details
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961