using System; namespace UnityEditor.Rendering { /// Bool flag saved in EditorPref /// Underlying enum type public struct EditorPrefBoolFlags : IEquatable, IEquatable> where T : struct, IConvertible { readonly string m_Key; /// The value as the underlying enum type used public T value { get => (T)(object)EditorPrefs.GetInt(m_Key); set => EditorPrefs.SetInt(m_Key, (int)(object)value); } /// The raw value public uint rawValue { get => (uint)EditorPrefs.GetInt(m_Key); set => EditorPrefs.SetInt(m_Key, (int)value); } /// Constructor /// Name of the Key in EditorPrefs to save the value public EditorPrefBoolFlags(string key) => m_Key = key; /// Test if saved value is equal to the one given /// Given value /// True if value are the same public bool Equals(T other) => (int)(object)value == (int)(object)other; /// Test if this EditorPrefBoolFlags is the same than the given one /// Given EditorPrefBoolFlags /// True if they use the same value public bool Equals(EditorPrefBoolFlags other) => m_Key == other.m_Key; /// Test if the given flags are set /// Given flags /// True: all the given flags are set public bool HasFlag(T v) => ((uint)(int)(object)v & rawValue) == (uint)(int)(object)v; /// Set or unset the flags /// Flags to edit /// Boolean value to set to the given flags public void SetFlag(T f, bool v) { if (v) rawValue |= (uint)(int)(object)f; else rawValue &= ~(uint)(int)(object)f; } /// Explicit conversion operator to the underlying type /// The EditorPrefBoolFlags to convert /// The converted value public static explicit operator T(EditorPrefBoolFlags v) => v.value; /// Or operator between a EditorPrefBoolFlags and a value /// The EditorPrefBoolFlags /// The value /// A EditorPrefBoolFlags with OR operator performed public static EditorPrefBoolFlags operator |(EditorPrefBoolFlags l, T r) { l.rawValue |= (uint)(int)(object)r; return l; } /// And operator between a EditorPrefBoolFlags and a value /// The EditorPrefBoolFlags /// The value /// A EditorPrefBoolFlags with AND operator performed public static EditorPrefBoolFlags operator &(EditorPrefBoolFlags l, T r) { l.rawValue &= (uint)(int)(object)r; return l; } /// Xor operator between a EditorPrefBoolFlags and a value /// The EditorPrefBoolFlags /// The value /// A EditorPrefBoolFlags with XOR operator performed public static EditorPrefBoolFlags operator ^(EditorPrefBoolFlags l, T r) { l.rawValue ^= (uint)(int)(object)r; return l; } } }