Creating an enum flags ObjectDrawer

SerializedProperties aren't used by the inspector because those require a Unity object, which tasks are not. You should be able to do something similar though by using the field within the task.
 
by using the field within the task.
What do you mean by this?

I'm not well versed in writing drawrers but I checked it out with a standard unity monobehaviour and it's as simple as this:

Code:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    _property.intValue = EditorGUI.MaskField(_position, _label, _property.intValue, _property.enumNames);
}


// How to reproduce the same with an ObjectDrawer?
public override void OnGUI(GUIContent label)
{
    var flagSettings = (EnumWithFlagsAttribute)attribute;
}
 
It would look something like this, where flagSettingsString is retrieved with Enum.GetName

Code:
value = EditorGUILayout.MaskField(label, (int)value, flagSettingsString);
 
Thanks that did the trick. Code is provided below should someone need it.


Code:
using System;
using System.Reflection;
using BehaviorDesigner.Editor;
using UnityEditor;
using UnityEngine;

//https://opsive.com/forum/index.php?threads/creating-an-enum-flags-objectdrawer.3029/#post-15005
// set this in editor folder
[CustomObjectDrawer(typeof(EnumFlagsBD))]
public class EnumFlagsBDDrawer : ObjectDrawer
{
    public override void OnGUI(GUIContent label)
    {
        var enumNames = Enum.GetNames(value.GetType());
        value = EditorGUILayout.MaskField(label, (int)value, enumNames);
    }
}


// set this in non-editor folder
using BehaviorDesigner.Runtime.Tasks;

public class EnumFlagsBD : ObjectDrawerAttribute
{
}
 
Top