This section describes the data type conversions and fields supported by PropertyField.
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.
以下の表は、バインドできるソースと対象となるデータ型の一覧です。
| ソースのデータ型 | INotifyValueChanged の対象データ型 |
|---|---|
long |
|
int |
|
double |
|
float |
|
char |
|
ノート: データ損失を防ぐために、PropertyField を使用するか、または以下の PropertyField がサポートするフィールドの表 に示す適切なデータ型を使用してください。
PropertyField がサポートするフィールドInspector ウィンドウに入力するときに、カスタムエディターがタイプに存在しない場合、バインディングシステムは InspectorElement.FillDefaultInspector() を呼び出します。これにより SerializedObject の各 SerializedProperty 用に PropertyField が作成されます。
各 PropertyField には一致するコントロールがあります。例えば、IntegerField は int を表し、Toggle は bool を表します。プロパティにサブプロパティがある場合は PropertyField にはFoldout コントロールがあります。その Foldout には、各サブプロパティの下に適切なデフォルトコントロールを持ちます。プロパティに対してカスタムの PropertyDrawer を作成した場合は、PropertyDrawer の CreatePropertyGUI() メソッドから返されるビジュアルツリーが代わりに使用されます。
ノート:
カスタム UI を作るときは、特定のコントロールが見つからない場合を除き PropertyField を使用しないでください。例えば、ビジュアルツリーにコントロールを作成し、それを Color にバインドするにはPropertyField ではなく、ColorField を使用します。これにより、ビジュアルツリーが軽量化され、操作がより早くなります。
PropertyField を使用すると、バインディング後に使用する具象フィールドを解決するため、余分なオーバーヘッドが発生します。この余分なステップはパフォーマンスに影響する可能性があります。ただし、PropertyField は、用途においては有益な場合があります。例えば、これはカスタムドロワーに対応しており、特定のプロパティの処理を個別化された方法で行うために使用できます。これにより、描画のためにフィールド型を推測する必要がなくなり、エラーを減らすことができます。
以下の表は、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 |