dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.58k stars 465 forks source link

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

Open axelorca opened 1 year ago

axelorca commented 1 year ago

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.

ninjuit commented 1 year ago

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.