Skip to content

Commit

Permalink
#207 - fixed a bug where Decorator Drawers are not affected by ShowIf…
Browse files Browse the repository at this point in the history
…/HideIf/EnableIf/DisableIf attributes
  • Loading branch information
dbrizov committed Apr 25, 2021
1 parent faa02a1 commit 6e24ead
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
56 changes: 21 additions & 35 deletions Assets/NaughtyAttributes/Scripts/Editor/Utility/NaughtyEditorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,33 @@ private static void PropertyField_Implementation(Rect rect, SerializedProperty p
}
else
{
GUIContent label = PropertyUtility.GetLabel(property);
bool anyDrawerAttribute = PropertyUtility.GetAttributes<DrawerAttribute>(property).Any();

if (!anyDrawerAttribute)
// Check if visible
bool visible = PropertyUtility.IsVisible(property);
if (!visible)
{
// Drawer attributes check for visibility, enableability and validator themselves,
// so if a property doesn't have a DrawerAttribute we need to check for these explicitly

// Check if visible
bool visible = PropertyUtility.IsVisible(property);
if (!visible)
{
return;
}

// Validate
ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(property);
foreach (var validatorAttribute in validatorAttributes)
{
validatorAttribute.GetValidator().ValidateProperty(property);
}
return;
}

// Check if enabled and draw
EditorGUI.BeginChangeCheck();
bool enabled = PropertyUtility.IsEnabled(property);
// Validate
ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(property);
foreach (var validatorAttribute in validatorAttributes)
{
validatorAttribute.GetValidator().ValidateProperty(property);
}

using (new EditorGUI.DisabledScope(disabled: !enabled))
{
propertyFieldFunction.Invoke(rect, property, label, includeChildren);
}
// Check if enabled and draw
EditorGUI.BeginChangeCheck();
bool enabled = PropertyUtility.IsEnabled(property);

// Call OnValueChanged callbacks
if (EditorGUI.EndChangeCheck())
{
PropertyUtility.CallOnValueChangedCallbacks(property);
}
using (new EditorGUI.DisabledScope(disabled: !enabled))
{
propertyFieldFunction.Invoke(rect, property, PropertyUtility.GetLabel(property), includeChildren);
}
else

// Call OnValueChanged callbacks
if (EditorGUI.EndChangeCheck())
{
// We don't need to check for enableIfAttribute
propertyFieldFunction.Invoke(rect, property, label, includeChildren);
PropertyUtility.CallOnValueChangedCallbacks(property);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Assets/NaughtyAttributes/Scripts/Test/_NaughtyComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class _NaughtyComponent : MonoBehaviour
[System.Serializable]
public class MyClass
{
[CurveRange(0, 0, 1, 1, EColor.Green)]
public AnimationCurve green;
}

[System.Serializable]
Expand Down

0 comments on commit 6e24ead

Please sign in to comment.