Создает обертку для свойства, полезно для создания обычных контролов GUI, работающих с SerializedProperty.
Большинство GUI-контролов EditorGUI и EditorGUILayout уже имеют переопределения, работающие с SerializedProperty.
Однако, контролы GUI, которые не обрабатывают SerializedProperty, вы можете обернуть в BeginProperty и EndProperty, как показано в следующем примере.
Вы можете использовать это также для своих собственных контролов GUI.
BeginProperty и EndProperty автоматически обрабатывают текст по умолчанию, жирный шрифт для изменений в префабах, откат к префабу через контекстное меню и установку 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 | The actual label to use for the control. |
| EditorGUI.PropertyScope | Create a new PropertyScope and begin the corresponding property. |