// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // First get the attribute since it contains the range for the slider if (attribute is DefaultObjectAttribute) { DefaultObjectAttribute range = (DefaultObjectAttribute)attribute; // Now draw the property as a Slider or an IntSlider based on whether it's a float or integer. if (property.propertyType == SerializedPropertyType.ObjectReference) { DisplayCheckboxAndControl(property, range, position, SetToNull, DisplayObjectField, ref isEnabled, ref objectValue); } else { EditorGUI.LabelField(position, label.text, "Use DefaultObject with objects."); } } }
static void SetToNull(SerializedProperty property, DefaultObjectAttribute range) { property.objectReferenceValue = null; }
static void DisplayObjectField(SerializedProperty property, DefaultObjectAttribute range, Rect position, ref Object value) { value = EditorGUI.ObjectField(position, value, property.objectReferenceValue.GetType(), true); }