private static void SetValue(SerializedProperty property, Type fieldType, Object value) { if (InterfaceReferenceDrawer.GetInterfaceType(fieldType) != null) { InterfaceReferenceDrawer.SetReferenceValue(property, value); } else { property.objectReferenceValue = value; } }
public static bool IsInterfaceReference(SerializedProperty property, Type fieldType) { if (property.propertyType == SerializedPropertyType.Generic) { if (fieldType != null) { return(InterfaceReferenceDrawer.GetInterfaceType(fieldType) != null); } } return(false); }
public static Type GetSearchType(Type fieldType, AutoPopulateAttribute autoPopulate) { Type searchType = fieldType; Type interfaceType = InterfaceReferenceDrawer.GetInterfaceType(searchType); if (interfaceType != null) { searchType = interfaceType; } if (autoPopulate.TypeOverride != null) { searchType = autoPopulate.TypeOverride; } return(searchType); }
public static bool NeedsPopulating(SerializedProperty property, Type fieldType) { if (!property.hasMultipleDifferentValues) { if (property.isArray) { return(property.arraySize == 0); } if (property.propertyType == SerializedPropertyType.ObjectReference) { return(property.objectReferenceValue == null); } if (IsInterfaceReference(property, fieldType)) { return(InterfaceReferenceDrawer.GetReferenceValue(property) == null); } } return(false); }
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); } }