Skip to content

Commit

Permalink
dbrizov#133 fixed expandable attr causing null ref exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
niggo1243 committed Sep 6, 2021
1 parent 489339d commit 51ab783
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
16 changes: 3 additions & 13 deletions Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,9 @@ protected void GetSerializedProperties(ref List<NaughtyProperty> outSerializedPr
{
do
{
NaughtyProperty naughtyProperty = new NaughtyProperty();
naughtyProperty.property = serializedObject.FindProperty(iterator.name);

naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute<ReadOnlyAttribute>(naughtyProperty.property);
naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute<EnableIfAttributeBase>(naughtyProperty.property);

naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute<ShowIfAttributeBase>(naughtyProperty.property);
naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(naughtyProperty.property);

naughtyProperty.specialCaseDrawerAttribute =
PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(naughtyProperty.property);

outSerializedProperties.Add(naughtyProperty);
outSerializedProperties.Add(
PropertyUtility.CreateNaughtyProperty(
serializedObject.FindProperty(iterator.name)));
}
while (iterator.NextVisible(false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G

EditorGUI.EndProperty();
}

private void DrawChildProperties(Rect rect, SerializedProperty property)
{
ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject;
Expand Down Expand Up @@ -180,7 +180,9 @@ private void DrawChildProperties(Rect rect, SerializedProperty property)
height = childHeight
};

NaughtyEditorGUI.PropertyField(childRect, new NaughtyProperty(){property=childProperty}, true);
//TODO since the depth can go deeper we cant just use one field. - need better caching and mapping here!
//_naughtyProperty ??= PropertyUtility.CreateNaughtyProperty(childProperty);
NaughtyEditorGUI.PropertyField(childRect, PropertyUtility.CreateNaughtyProperty(childProperty), true);

yOffset += childHeight;
}
Expand Down
17 changes: 17 additions & 0 deletions Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ public static T[] GetAttributes<T>(SerializedProperty property) where T : class
return (T[])fieldInfo.GetCustomAttributes(typeof(T), true);
}

public static NaughtyProperty CreateNaughtyProperty(SerializedProperty property)
{
NaughtyProperty naughtyProperty = new NaughtyProperty();
naughtyProperty.property = property;

naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute<ReadOnlyAttribute>(naughtyProperty.property);
naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute<EnableIfAttributeBase>(naughtyProperty.property);

naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute<ShowIfAttributeBase>(naughtyProperty.property);
naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(naughtyProperty.property);

naughtyProperty.specialCaseDrawerAttribute =
PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(naughtyProperty.property);

return naughtyProperty;
}

public static GUIContent GetLabel(SerializedProperty property)
{
LabelAttribute labelAttribute = GetAttribute<LabelAttribute>(property);
Expand Down

0 comments on commit 51ab783

Please sign in to comment.