このページは PropertyField がサポートするデータ型変換とフィールドを説明します。
UI Toolkit のほとんどのビルトインコントロールは、特定のデータ型に対して INotifyValueChanged インターフェースを実装しています。例えば、DoubleField は INotifyValueChanged<Double> を実装しています。つまり、 DoubleField コントロールを double 型のプロパティにバインドできます。バインディングシステムを使えば、もっと多くのデータ型をバインドすることができます。例えば、int 型のプロパティを DoubleField にバインドすることができます。
以下の表は、バインドできるソースと対象となるデータ型の一覧です。
| ソースのデータ型 | INotifyValueChanged の対象データ型 |
|---|---|
long |
|
int |
|
double |
|
float |
|
char |
|
ノート: データ損失を防ぐために、PropertyField を使用するか、または以下の PropertyField がサポートするフィールドの表 に示す適切なデータ型を使用してください。
PropertyField がサポートするフィールドWhen the Inspector window is populated, if a custom Editor does not 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 for 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.
Note: When you create 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 the operations faster.
以下の表は、PropertyField がサポートするフィールドとそのデータ型の一覧です。
| フィールド | データ型 |
|---|---|
BoundsField |
Bounds |
BoundsIntField |
BoundsInt |
ColorField |
Color |
CurveField |
AnimationCurve |
FloatField |
float |
GradientField |
Gradient |
Hash128Field |
Hash128 |
IntegerField |
int |
IntegerField |
int (ArraySize 用) |
LayerMaskField |
unit |
LongField |
long |
ObjectField |
UnityEngine.Object |
PopupField<string> |
Enum |
RectField |
Rect |
RectIntField |
RectInt |
TextField |
string |
TextField maxLength=1 の場合。 |
char |
Toggle |
bool |
Vector2Field |
Vector2 |
Vector2IntField |
Vector2Int |
Vector3Field |
Vector3 |
Vector3IntField |
Vector3Int |
Vector4Field |
Vector4 |