MyBox
MyBox copied to clipboard
Enum Flags throw error if user already defined Everything/Nothing
First of all, thanks for creating this great tool.
My issue arises when creating enum flags, I usually already include the everything and nothing in my own code. For example:
[System.Flags]
public enum COLLIDEWITH {
Nothing = 0,
Everything = ~0,
Player = 1 << 1,
Enemy = 1 << 2,
Wall = 1 << 3,
}
Implementing an enum flag like above in a monobehaviour will prevent the inspector from being drawn and writes an error to the console:
IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEditor.MaskFieldGUI.CalculateMaskValues (System.Int32 mask, System.Int32[] flagValues, System.Int32[]& optionMaskValues) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.MaskFieldGUI.GetMenuOptions (System.Int32 mask, System.String[] flagNames, System.Int32[] flagValues, System.String& buttonText, System.String& buttonMixedValuesText, System.String[]& optionNames, System.Int32[]& optionMaskValues, System.Int32[]& selectedOptions, System.Type enumType) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.MaskFieldGUI.DoMaskField (UnityEngine.Rect position, System.Int32 controlID, System.Int32 mask, System.String[] flagNames, System.Int32[] flagValues, UnityEngine.GUIStyle style, System.Int32& changedFlags, System.Boolean& changedToValue, System.Type enumType) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.EditorGUI.EnumFlagsField (UnityEngine.Rect position, UnityEngine.GUIContent label, System.Int32 enumValue, System.Type enumType, System.Boolean includeObsolete, UnityEngine.GUIStyle style) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.EditorGUI.EnumPopup (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.EditorGUI.DefaultPropertyField (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
MyBox.Internal.FoldoutAttributeHandler.Body () (at ./Library/PackageCache/com.domybest.mybox@3950fccd96/Attributes/FoldoutAttribute.cs:105)
MyBox.Internal.FoldoutAttributeHandler.OnInspectorGUI () (at ./Library/PackageCache/com.domybest.mybox@3950fccd96/Attributes/FoldoutAttribute.cs:75)
MyBox.Internal.UnityObjectEditor.OnInspectorGUI () (at ./Library/PackageCache/com.domybest.mybox@3950fccd96/Tools/Internal/UnityObjectEditor.cs:34)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass76_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <50e19b0ed93a4256b2e454b4acec2d48>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
My guess my code seems to clash with something in MyBox, I guess having to do with #47. I found out I could fix it by not declaring everything and nothing anymore, which is okay for me. Not sure if this can be fixed, otherwise a more specific error telling the user not to declare everything and nothing themselves might be helpful, because it took me some time before I figured out what was wrong.