Ejemplo n.º 1
0
        /// <summary>
        /// Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.
        /// </summary>
        public static string GetString(string key, string defaultValue = "", bool?useSecurePrefs = null)
        {
            // if not using secure prefs, or we provide an override then just fall through to standard call.
            if ((!UseSecurePrefs && !useSecurePrefs.HasValue) || (useSecurePrefs.HasValue && useSecurePrefs.Value == false))
            {
                return(JSONPrefs.GetString(key, defaultValue));
            }

            // using secure prefs.
            var prefsEntryBytes = GetDecryptedPrefsEntry(key, ItemType.String);

            if (prefsEntryBytes != null)
            {
                return(Encoding.UTF8.GetString(prefsEntryBytes, 0, prefsEntryBytes.Length));
            }

            // if the prefs entry was not found and we are auto converting then try and get and replace any unencrypted value.
            if (AutoConvertUnsecurePrefs && JSONPrefs.HasKey(key))
            {
                var value = JSONPrefs.GetString(key, defaultValue);
                SetString(key, value);
                JSONPrefs.DeleteKey(key);
                return(value);
            }

            // nothing found so return the default value
            return(defaultValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.
        /// </summary>
        public static void DeleteKey(string key, bool?useSecurePrefs = null)
        {
            // if not using secure prefs, or we provide an override then just fall through to standard call.
            if ((!UseSecurePrefs && !useSecurePrefs.HasValue) || (useSecurePrefs.HasValue && useSecurePrefs.Value == false))
            {
                JSONPrefs.DeleteKey(key);
                return;
            }

            JSONPrefs.DeleteKey(EncryptKey(key));
            if (AutoConvertUnsecurePrefs)
            {
                JSONPrefs.DeleteKey(key);
            }
        }