Please make enum flags always use EnumFlagsField as default prperty drawer

I don’t know why you need us to create CustomPropertyDrawer just for having enum flag use EnumFlagsField

Any enum that has FlagsAttribute should just use EnumFlagsField as default PropertyDrawer everywhere

It could be checked easily with this code

fieldInfo.FieldType.CustomAttributes.Any((attribute) => attribute.AttributeType == typeof(FlagsAttribute))
2 Likes

I guess the reason this may be difficult for them to do, is that an enum (to my knowledge) with the [Flags] attribute, still increases each value by 1

i.e.

[Flags]
enum MyFlags
{
a, //0
b, //1
c, //2
d, //3
}

and for flags to work properly they would need to be as followed

enum MyFlags
{
a = 1, //1
b =2 , //2
c = 4, //4
e = 8, //8
}

But I too find it annoying there is no default way to draw a lot of things which unity has methods for drawing, flags being one of them. It annoys me more that the EditorGUI.MaskField shows ‘mixed’ when two values are selected, rather than how it works on say LayerMasks showing up to 3 selected values before it goes mixed.

just fyi, this is how we draw the mask field for anybody that is curious

    public override void OnGUI(Rect position,
                                SerializedProperty property,
                                GUIContent label)
    {
        EditorGUI.BeginChangeCheck();
        uint a = (uint)(EditorGUI.MaskField(position, label, property.intValue, property.enumNames));
        if (EditorGUI.EndChangeCheck())
        {
            property.intValue = (int)a;
        }
    }

@BinaryCats Not really, flag could be define as 0,1,2,3 if the person who create it know what they really want to do

In fact the person who create enum with [flags] would really have knowledge about how to define enum value. So it’s their responsible to define enum value properly

It just that unity should be responsible for drawing all enum with [flags] by EnumFlagsField (and normal enum by EnumPopup) by default