sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.09k stars 1.11k forks source link

EnumTypeDrawer uses obsolete unity api #891

Open SirMetathyst opened 5 years ago

SirMetathyst commented 5 years ago

Quite a while ago I had problems with enums in the inspector, i.e. they were not being set properly and I got exceptions when trying to change them

changed this code:

public class EnumTypeDrawer : ITypeDrawer {

        public bool HandlesType(Type type) {
            return type.IsEnum;
        }

        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target) {
            if (memberType.IsDefined(typeof(FlagsAttribute), false)) {
                return EditorGUILayout.EnumMaskField(memberName, (Enum)value);
            }
            return EditorGUILayout.EnumPopup(memberName, (Enum)value);
        }
    }

to

public class EnumTypeDrawer : ITypeDrawer
{
    public bool HandlesType (Type type)
    {
        return type.IsEnum;
    }

    public object DrawAndGetNewValue (Type memberType, string memberName, object value, object target)
    {
        if (memberType.IsDefined (typeof (FlagsAttribute), false))
        {
            return EditorGUILayout.EnumFlagsField (memberName, (Enum) value);
        }
        return EditorGUILayout.EnumPopup (memberName, (Enum) value);
    }
}

and everything worked as expected. EnumFlagsField (latest api) has the same signature as the old one but is broken now. Has anyone else had this issue before?