Skip to main content

EnumGameSettingAccess

A class in Root.Township, Alta.Utilities.

Settings field access for an enum setting, offered as a list of names. Can show custom display names, matched to the enum values by order.

Constructors​

MemberWhat it is
EnumGameSettingAccess()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

5 private and internal fields
MemberWhat it is
private string[] customNamesDisplay names, in the enum's order.
private Dictionary<string, string> customToEnumNamesBacking field for CustomToEnumNames.
private Dictionary<string, string> enumToCustomNamesBacking field for EnumToCustomNames.
private bool isSetupSet once the name maps are built. Nothing reads it.
private bool isUsingCustomNamesWhether to show customNames instead of the enum names.

Properties​

2 private and internal properties
MemberWhat it is
private Dictionary<string, string> CustomToEnumNames { get; }Display name to enum name map, built on first use.
private Dictionary<string, string> EnumToCustomNames { get; }Enum name to display name map, built on first use.

Methods​

MemberWhat it is
override async Task<string[]> GetPossibleValue()The option names: the custom names if turned on, otherwise the enum's names.
override string GetValue()The current value as a name (the custom name if turned on).
override void SetValue(string value)Parses the name (mapping a custom name back first), sets the property and raises OnModifed.
2 private and internal methods
MemberWhat it is
private void OnValidate()Editor: fills the custom names from the enum names when custom names are on but empty.
private void SetupCustomNameMappings()Builds both name maps by index. Needs one custom name per enum value.