dbrizov / NaughtyAttributes

Attribute Extensions for Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(bug) Excessive Spacing with the ShowIf/HideIf attributes in Nested Arrays

axelorca opened this issue · comments

commented

Hi there!
I'm encountering an issue with the ShowIf and HideIf attributes. It doesn't seem to be removing the spacing between properties. I'm not using any Space attribute, the spacings are just the default spacing value between a property and another
bug
I kind of got around it by using [Space(negative int)] but it doesn't give pleasing results...
Any possibility to fix this??
PS: The variables are displayed in nested arrays.

If you go into the NaughtyAttributes codebase, find PropertyDrawerBase.cs, and replace GetPropertyHeight with this, it will fix it.

sealed override public float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
    bool visible = PropertyUtility.IsVisible(property);
    if (!visible)
    {
        return -EditorGUIUtility.standardVerticalSpacing;
    }
    return GetPropertyHeight_Internal(property, label);
}

Basically, even when an element is hidden, Unity still draws the default height for a new element, so I solved it by just applying a negative height for the hidden elements.