I'm having an issue with enum values being reflected as their numeric values in the inspector when used in a nested array with Unity. Here's a cut down example of the code I'm trying to use.
public enum EnumType
{
Enum1,
Enum2
}
public class ContainerClass : MonoBehavior
{
[Serializable]
public class Constants
{
[Serializable]
public class SubConstants
{
/*...*/
public EnumType EnumVals[] = null;
}
public SubConstants SubConsts = new SubConstants();
}
[SerializeField]List<Constants> _Attributes = new List<Constants>();
}
So what I'm seeing is that I can create and modify the list of Constants but when I go to edit the array of EnumType in SubConstants, it only shows numeric values and not a drop down box of values. I've also tried making the List an array with no change.
Seems like the Unity Inspector has a bug with reflected type discovery. Rearranging the nesting of the classes as follows makes it work:
using System;
using System.Collections.Generic;
using UnityEngine;
public enum EnumType
{
Enum1,
Enum2
}
[Serializable]
public class SubConstants
{
/*...*/
public EnumType[] EnumVals = null;
}
public class ContainerClass : MonoBehaviour
{
[Serializable]
public class Constants
{
public SubConstants SubConsts = new SubConstants();
}
[SerializeField]List<Constants> _Attributes = new List<Constants>();
}