private void ForceRepopulate(object data) { SerializedProperty property = data as SerializedProperty; AutoPopulateAttribute autoPopulate = attribute as AutoPopulateAttribute; if ((property != null) && (autoPopulate != null)) { property.serializedObject.Update(); AutoPopulateUtils.PopulateValue(fieldInfo.FieldType, property, autoPopulate); property.serializedObject.ApplyModifiedProperties(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { AutoPopulateAttribute autoPopulate = attribute as AutoPopulateAttribute; if (CanAutoPopulate(property, autoPopulate)) { bool wasEnabled = GUI.enabled; GUI.enabled = GetEditable(property, autoPopulate); bool populated = false; if (AutoPopulateUtils.NeedsPopulating(property, fieldInfo.FieldType)) { populated = AutoPopulateUtils.PopulateValue(fieldInfo.FieldType, property, autoPopulate); } else { populated = true; } GUIContent tweakedLabel = new GUIContent(label.text, GetIcon(autoPopulate, populated), GetTooltip(property, autoPopulate)); if (AutoPopulateUtils.IsInterfaceReference(property, fieldInfo.FieldType)) { InterfaceReferenceDrawer.PropertyField(position, property, fieldInfo, tweakedLabel); } else { EditorGUI.PropertyField(position, property, tweakedLabel); } GUI.enabled = wasEnabled; HandlePopup(position, property, autoPopulate); } else { GUIContent tweakedLabel = new GUIContent(label.text, ErrorIcon, GetErrorTooltip()); EditorGUI.PropertyField(position, property, tweakedLabel); } }