SerializedPropertyを GUI で管理しやすくするようにするためのプロパティーのラッパーである GUI グループを作成します
ほとんどのEditorGUIとEditorGUILayoutの GUI コントロールはすでに SerializedProperty で動作するオーバーロードを持ち合わせています。
ですが、以下の例のように SerializedProperty でハンドリングできないものに関しては BeginProperty と EndProperty でラップしてその内側に処理を書くことで GUI を制御することが可能です。
独自の GUI コントロールを作成する場合にも使用することができます。
複数のオブジェクトを編集するとき、プロパティーの値が異なる場合、BeginProperty と EndProperty はデフォルトのラベルに、プレハブに Bold のフォントを上書き、右クリックしてプレハブにメニューに戻すことや showMixedValue を True に設定するなどの処理を自動的に行います。
class ExampleClass {
// A slider function that takes a SerializedProperty
void Slider (Rect position, SerializedProperty prop, float leftValue, float rightValue, GUIContent label) {
using (var scope = new EditorGUI.PropertyScope (position, label, prop)) {
label = scope.content;
EditorGUI.BeginChangeCheck ();
var newValue = EditorGUI.Slider (position, label, prop.floatValue, leftValue, rightValue);
// Only assign the value back if it was actually changed by the user.
// Otherwise a single value will be assigned to all objects when multi-object editing,
// even when the user didn't touch the control.
if (EditorGUI.EndChangeCheck ())
prop.floatValue = newValue;
}
}
}
See Also: BeginProperty.
| content | 制御に使用する実際のラベル |
| EditorGUI.PropertyScope | 新しい PropertyScope を作成し、対応するプロパティーを開始します。 |