Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

PropertyScope

class in UnityEditor

Description

Create a Property wrapper, useful for making regular GUI controls work with 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.

#pragma strict
// A slider function that takes a SerializedProperty
function Slider(position: Rect, prop: SerializedProperty, leftValue: float, rightValue: float, label: GUIContent) {
	var scope: var = new EditorGUI.PropertyScope(position, label, prop);
	 {
		label = scope.content;
		EditorGUI.BeginChangeCheck();
		var newValue: var = EditorGUI.Slider(position, label, prop.floatValue, leftValue, rightValue);
		// even when the user didn't touch the control.
		if (EditorGUI.EndChangeCheck())
			prop.floatValue = newValue;
	}
}

See Also: BeginProperty.

Variables

contentThe actual label to use for the control.

Constructors

EditorGUI.PropertyScopeCreate a new PropertyScope and begin the corresponding property.

Did you find this page useful? Please give it a rating: