Dynamic Enums - edcasillas/unity-common-utils GitHub Wiki

Dynamic Enums act as a replacement for C# enums that can be modified in the Inspector, so when new values are required you don't need to touch the code.

Internally, C# enums work as integers and you can also easily retrieve it's name as string. Dynamic Enums work the same way, you can use them as int or string.

Dynamic enums are created in the DynamicEnums asset. To access this asset, go to menu Tools->Dynamic Enums.... This will create the asset if it doesn't already exist. You can then add a value to the Enums collection, and set a name and values for that enum. Don't forget to click the Reload button once you finish editing the asset, so new enums and values are immediately available for you.

Once the dynamic enum is defined, you can create an inspector field in a GameObject to show a selection list (just like a normal enum) by adding the DynamicEnumAttribute to the field:

[DynamicEnum("Name of the enum in the asset")]
[SerializeField] private int myEnumValue; // Will store the enum value as int.

[DynamicEnum("Name of the enum in the asset")]
[SerializeField] private string myOtherEnumValue; // Will store the enum value as string.

These are specially useful when you use enums for inspector configuration only and your code doesn't really care about the named values of the enum. But this is NOT recommended when you're going to add stuff like switch-case's over the enum values or when your enum values are not likely to be modified, in that case, a classic enum is more than enough; it's a case by case decision.

In case you need to convert the string value to int or viceversa, you can use the DynamicEnumManager.IntToValue and ValueToInt methods.