Example #1
0
        public static string GetString(string key, string defaultValue = "")
        {
            if (!PlayerPrefs.HasKey(key))
            {
                return(defaultValue);
            }
            string result = SecuritySystem.Decrypt(KEY, PlayerPrefs.GetString(key));

            return(result);
        }
Example #2
0
        public static int GetInt(string key, int defaultValue = 0)
        {
            string value = SecuritySystem.Decrypt(KEY, PlayerPrefs.GetString(key));
            int    result;

            if (int.TryParse(value, out result))
            {
                return(result);
            }
            return(defaultValue);
        }
Example #3
0
        public static float GetFloat(string key, float defaultValue = 0.0f)
        {
            string value = SecuritySystem.Decrypt(KEY, PlayerPrefs.GetString(key));
            float  result;

            if (float.TryParse(value, out result))
            {
                return(result);
            }
            return(defaultValue);
        }
Example #4
0
        public static void SetObject <T>(string key, T value)
        {
            MemoryStream    stream    = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(stream, value);

            string result = Convert.ToBase64String(stream.GetBuffer());

            PlayerPrefs.SetString(key, SecuritySystem.Encrypt(KEY, result));
            stream.Close();
        }
Example #5
0
        public static T GetObject <T>(string key)
        {
            string data = SecuritySystem.Decrypt(KEY, PlayerPrefs.GetString(key));

            byte[]          buffer    = Convert.FromBase64String(data);
            MemoryStream    stream    = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();

            stream.Position = 0;

            T result = (T)formatter.Deserialize(stream);

            stream.Close();

            return(result);
        }
Example #6
0
 public static void SetString(string key, string value)
 {
     PlayerPrefs.SetString(key, SecuritySystem.Encrypt(KEY, value.ToString()));
 }