Creating a Header ObjectDrawer

KOKOStern

New member
I was surprised that BehaviorDesigner.Runtime.ObjectDrawers is almost empty and there's only the float and int sliders and nothing else.

One of the basic things I use often is a header to separate variables once I have more than a few. One of the most basic of things and I'm wondering why it isn't found in the namespace above. This means I set out to make it with my limited drawers knowledge:

Code:
public class VarHeaderAttribute : ObjectDrawerAttribute
    {
        public string desc;

        public VarHeaderAttribute(string desc)
        {
            this.desc = desc;
        }
    }
    
[CustomObjectDrawer(typeof(VarHeaderAttribute))]
public class VarHeaderDrawer : ObjectDrawer
    {
        public override void OnGUI(GUIContent label)
        {
            base.OnGUI(label);
            VarHeaderAttribute header = attribute as VarHeaderAttribute;
            EditorGUILayout.LabelField(header.desc, EditorStyles.boldLabel);
        }
    }

Then in use:

Code:
  [VarHeader("Movement")]
        [SerializeField]
        private FloatReference _distToTarget;
        [SerializeField]
        private FloatReference _moveSpeed;
        [SerializeField]
        private FloatReference _rotSpeed;

Sadly this code shows a label but hides the actual variable, which is of course not what I intended.

2019-01-08_17-22-38.png

How do I make this simple thing work?
 
A generic header that does not show the actual field isn't supported by object drawers. I can add support for the header attribute to the next version though.
 
Ahh yeah please do. That's a rather basic thing I feel. As tasks have a lot of variables it's a QoL feature to separate them with headers.

Thanks for the reply.
 
I'll second or third this request. I made the same request in the Unity Forums and just want to make sure it goes here as well.

Headers to be able to organize variables in custom tasks would be very helpful.

Thanks
Allan
 
Top