Class EnumValues<TValue>
Namespace: Aspid.FastTools.Enums
Assembly: Aspid.FastTools.dll
A serializable dictionary that maps each member of a chosen enum to a value of type
TValue. Supports both regular and [Flags] enums.
[Serializable]
public sealed class EnumValues<TValue> : IEnumerable<KeyValuePair<Enum, TValue?>>, IEnumerable, ISerializationCallbackReceiver
Type Parameters
TValue
The type of the value associated with each enum member.
Inheritance
Implements
IEnumerable<KeyValuePair<Enum, TValue?>>, IEnumerable, ISerializationCallbackReceiver
Extension Methods
TextInputBaseFieldTextSelectionExtensions.AddOnCursorIndexChange<EnumValues<TValue>, TValue>(EnumValues<TValue>, Action), TextInputBaseFieldTextSelectionExtensions.AddOnSelectIndexChange<EnumValues<TValue>, TValue>(EnumValues<TValue>, Action), INotifyValueChangedExtensions.AddValueChanged<EnumValues<TValue>, TValue>(EnumValues<TValue>, EventCallback<ChangeEvent<TValue>>), ProfilerMarkerExtensionsForGenerator.Marker<EnumValues<TValue>>(EnumValues<TValue>), TextInputBaseFieldTextSelectionExtensions.RemoveOnCursorIndexChange<EnumValues<TValue>, TValue>(EnumValues<TValue>, Action), TextInputBaseFieldTextSelectionExtensions.RemoveOnSelectIndexChange<EnumValues<TValue>, TValue>(EnumValues<TValue>, Action), INotifyValueChangedExtensions.RemoveValueChanged<EnumValues<TValue>, TValue>(EnumValues<TValue>, EventCallback<ChangeEvent<TValue>>), TextInputBaseFieldExtensions.SetAutoCorrection<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetCursorIndex<EnumValues<TValue>, TValue>(EnumValues<TValue>, int), TextInputBaseFieldExtensions.SetDelayed<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetDoubleClickSelectsWord<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldExtensions.SetHideMobileInput<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldExtensions.SetHidePlaceholderOnFocus<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldExtensions.SetHideSoftKeyboard<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), SliderExtensions.SetHighValue<EnumValues<TValue>, TValue>(EnumValues<TValue>, TValue), TextInputBaseFieldExtensions.SetKeyboardType<EnumValues<TValue>, TValue>(EnumValues<TValue>, TouchScreenKeyboardType), BaseFieldExtensions.SetLabel<EnumValues<TValue>, TValue>(EnumValues<TValue>, string), SliderExtensions.SetLowValue<EnumValues<TValue>, TValue>(EnumValues<TValue>, TValue), TextInputBaseFieldExtensions.SetMaskChar<EnumValues<TValue>, TValue>(EnumValues<TValue>, char), TextInputBaseFieldExtensions.SetMaxLength<EnumValues<TValue>, TValue>(EnumValues<TValue>, int), TextInputBaseFieldExtensions.SetPassword<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldExtensions.SetPlaceholder<EnumValues<TValue>, TValue>(EnumValues<TValue>, string), TextInputBaseFieldExtensions.SetReadOnly<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectAllOnFocus<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectAllOnMouseUp<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetSelectIndex<EnumValues<TValue>, TValue>(EnumValues<TValue>, int), TextInputBaseFieldTextSelectionExtensions.SetSelectable<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), TextInputBaseFieldTextSelectionExtensions.SetTripleClickSelectsLine<EnumValues<TValue>, TValue>(EnumValues<TValue>, bool), INotifyValueChangedExtensions.SetValue<EnumValues<TValue>, TValue>(EnumValues<TValue>, TValue, bool)
Examples
Map a damage type to a color:
public class HitEffect : MonoBehaviour
{
[SerializeField] private EnumValues<Color> _damageColors;
public Color GetColor(DamageType type) =>
_damageColors.GetValue(type);
}
Remarks
The enum type is selected in the Inspector via a TypeSelectorAttribute
and stored as an assembly-qualified name. All entries are initialized lazily on first access.
When the enum type is already known at compile time, prefer
EnumValues<T1, T2> — its Inspector type-picker is read-only.
For [Flags] enums EnumValues<T>.Equals uses flag-containment semantics
with special handling for the zero (None) value — two values are considered equal
only when both are zero or both are non-zero and one has all bits of the other set.
EnumValues<T>.GetValue returns the configured default value when no entry matches the lookup key.
For [Flags] enums multiple entries may match a single lookup value; an exact-key entry
always wins first, and only if none exists does the first entry (in serialized order) whose
bits are all contained in the lookup value win.
Iteration via EnumValues<T>.GetEnumerator yields only the explicitly configured entries and
does not include the default value.
Internal hot paths are wrapped in profiler markers; define the
ASPID_FAST_TOOLS_UNITY_PROFILER_DISABLED scripting symbol to compile them out.
Methods
Equals(Enum, Enum)
Determines whether two enum values should be considered equal for lookup purposes. The first argument is the value being looked up; the second is the entry's stored key.
public bool Equals(Enum enumValue1, Enum enumValue2)
Parameters
enumValue1 Enum
The lookup value (must contain the entry's bits to match).
enumValue2 Enum
The stored entry key.
Returns
For regular enums: true when both values are identical.
For [Flags] enums: true when enumValue1
has all bits of enumValue2 set, with the additional rule that
the zero (None) value is only equal to another zero value.
Values of a different enum type than the configured one are never equal,
and neither is null.
GetEnumerator()
Returns a struct enumerator over the explicitly configured (key, value) pairs in
serialized order — foreach binds to it directly and does not allocate.
Does not include the default value or entries with an unresolved key.
public EnumValuesEnumerator<Enum, TValue> GetEnumerator()
Returns
EnumValuesEnumerator<Enum, TValue>
GetValue(Enum)
Returns the value mapped to enumValue,
or the configured default value if no mapping exists.
A value of a different enum type than the configured one never matches.
public TValue? GetValue(Enum enumValue)
Parameters
enumValue Enum
The enum member to look up.
Returns
TValue?
The mapped value, or the default value when no entry matches. A reference-type
TValue left unassigned in the Inspector is null.