Exemple #1
0
        /// <summary>
        /// Used to check the state that is holding an `enum` inside instead of `bool`
        /// Note that the serialized thing is the string of that enum's name (the English name), not an integer or string-as-integer.
        /// If 2 `enum` have the same value English name, one `enum`'s serialized name will be usable with the other.
        /// </summary>
        /// <typeparam name="ENUM">Type of the enum key.</typeparam>
        /// <typeparam name="ENUM2">Type of the desired state.</typeparam>
        public static ENUM2 State <ENUM, ENUM2>(ENUM e)
            where ENUM : struct, Enum
            where ENUM2 : struct, Enum
        {
            string enumString = PlayerPrefs.GetString(PersistentInternal.EnumToKey(e));

            return(Enum.TryParse <ENUM2>(enumString, out var parsed) ? parsed : default);
Exemple #2
0
 /// <summary>
 /// Get an `int` index of the `enum` key <param name="e">.
 /// </summary>
 public static void Index <ENUM>(ENUM e, int setTo)
     where ENUM : struct, Enum
 => PlayerPrefs.SetInt(PersistentInternal.EnumToKey(e), setTo);
Exemple #3
0
 /// <summary>
 /// Use an another set of `enum` instead of `bool` for a state to remember something that has more than 2 choices but still finite.
 /// It is saved as a string representation of <param name="setTo">.
 /// </summary>
 /// <typeparam name="ENUM">Type of the enum key.</typeparam>
 /// <typeparam name="ENUM2">Type of the state to remember.</typeparam>
 public static void State <ENUM, ENUM2>(ENUM e, ENUM2 setTo)
     where ENUM : struct, Enum
     where ENUM2 : struct, Enum
 => PlayerPrefs.SetString(PersistentInternal.EnumToKey(e), setTo.ToString());