- Home /
Array to match Enum in Inspector
I'm making a serialized bool array, which should ideally be changeable in the inspector. It's part of a class, Profile, that doesn't inherit from MonoBehaviour. My WorldManager class has a public instance of Profile. Profile has an enum and some arrays like this:
public enum MathModule {Addition, Multiplication, Subtraction, Division, Exponents};
public bool[] mathEnabled = new bool[5];
public float[] minimum = new float[5];
public float[] maximum = new float[5];
And in the inspector, it looks like this: It is not entirely necessary for me to look at it in the inspector, as the final product will have users editing them in GUI. But it's nice to see what I'm looking at as I'm developing, and it will come in handy in other situations as well.
So far, the only other questions I can find on the topic are how to change enums at runtime. And maybe I could use a dictionary object, but that's far less than ideal. I want to make an array that relates to the enum values, and shows those values in the inspector.
Making a subclass, MathModuleStats or something like that, makes more sense than I'm willing to admit at the moment, but I'm also looking for what to do when that doesn't make sense.
Answer by FlaSh-G · Jul 01, 2017 at 10:07 AM
What you need is a custom PropertyDrawer. Here's one that does what you want.
Though this does point me in the right direction, the example provided is for a bit$$anonymous$$ask enum, and I don't know how to modify it to my specifications. I will look into Custom Property Drawers and get back with you on if it works or not.