1
\$\begingroup\$

I use GUILayout.Space(px) to add space after some property. Property is drawn using PropertyDrawer via PropertyAttribute.

Inspector Window

You can see that Min Max Prop displays properly inside targetObject(AudioPlayer) but if it's in nested object like Engine, Engine Multi, Filed it adds space to the targetObject not the nested object itself.

\$\endgroup\$
2
  • \$\begingroup\$ sharing the code might help us get on the right track and fix the problem. \$\endgroup\$
    – Uri Popov
    Oct 30 '17 at 9:37
  • \$\begingroup\$ @UriPopov can't do that right now. pastebin.com/KkUPyYu6 - the same principle to how that is done. HideInDerivedAttribute simply empty class that inherits PropertyAttribute. The problem is not in my code but in Unity API. It should target nested object, instead, it targets object at the top of the hierarchy. I'm looking for some workaround. If I get home, maybe I will be able to post related code. \$\endgroup\$ Oct 30 '17 at 10:45
1
\$\begingroup\$

It is possible in nested objects by adding height to overridden GetPropertyHeight() of PropertyDrawer.

Solution

namespace Kimo.Assistance.UTILITY
{
#if UNITY_EDITOR
    [CustomEditor(typeof(MultiSupportPropertyAttribute))]
    [CanEditMultipleObjects]
    public class MultiSupportPropertyAttributeDrawer : PropertyDrawer
    {
        private MultiSupportPropertyAttribute _attribute;

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (this._attribute == null)
                this._attribute = this.attribute as MultiSupportPropertyAttribute;

            return base.GetPropertyHeight(property, label) + this._attribute.GetPropertyExtensionHeight();
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //foreach (var attribute in fieldInfo.GetCustomAttributes(false))
            //{
            //  (attribute as MultiSupportPropertyAttribute).DrawInInspector(position, property, label);
            //}

            this._attribute.BeginDrawInInspector(position, property, label);
            this._attribute.DrawInInspector(position, property, label);
            this._attribute.EndDrawInInspector(position, property, label);
        }
    }
#endif
}

GetPropertyExtensionHeight() - is my method that needs to be overridden. It just adds some space instead of giving a full new space size.

Usage example

public override float GetPropertyExtensionHeight()
{
    if (this._compactFormat)
        return InspectorUtility.DEFAULT_FIELD_HEIGHT;
    return 0;
}

Works like a charm:

Working example

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.