totalPosition | @param totalPosition Прямоугольник на экране, используемый для контрола, включая текст, если применимо. |
label | @param label Необязательный текст перед слайдером. Передайте null, чтобы использовать имя из SerializedProperty. Используйте GUIContent.none, чтобы не отображать текст. |
property | @param property SerializedProperty, используемый контролом. |
GUIContent The actual label to use for the control.
Создает обертку для свойства, полезно для создания обычных контролов GUI, работающих с SerializedProperty.
Most EditorGUI and EditorGUILayout GUI controls already have overloads that work with SerializedProperty.
However, for GUI controls that don't handle SerializedProperty you can wrap them inside BeginProperty and EndProperty as shown in the example below.
You can use this for your own custom GUI controls too.
BeginProperty and EndProperty automatically handle default labels, bold font for Prefab overrides, revert to Prefab right click menu, and setting showMixedValue to true if the values of the property are different when multi-object editing.
using UnityEngine; using UnityEditor;
class Example : MonoBehaviour { // A slider function that takes a SerializedProperty void Slider(Rect position, SerializedProperty property, float leftValue, float rightValue, GUIContent label) { label = EditorGUI.BeginProperty(position, label, property);
EditorGUI.BeginChangeCheck(); var newValue = EditorGUI.Slider(position, label, property.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()) { property.floatValue = newValue; } EditorGUI.EndProperty(); } }
See Also: EndProperty.