Exemplo n.º 1
0
 public virtual void OnAppPause()
 {
     GameLog.Debug("OnAppPause");
     UserPrefs.SetDateTime("AppSession.StartTime", this.StartTime);
     this.PauseTime = DateTime.UtcNow;
     UserPrefs.SetDateTime("AppSession.PauseTime", this.PauseTime);
 }
Exemplo n.º 2
0
 public static void ClearPrefs()
 {
     UserPrefs.Remove("GameState.FirstStartDateTime");
     UserPrefs.Remove("AppSession.StartTime");
     UserPrefs.Remove("AppSession.PauseTime");
     UserPrefs.Remove("AppSession.SessionId");
 }
Exemplo n.º 3
0
 public static float GetFloat(string key, float defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         return(PlayerPrefs.GetFloat(key));
     }
     return(defaultValue);
 }
Exemplo n.º 4
0
 public static int GetInt(string key, int defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         return(PlayerPrefs.GetInt(key));
     }
     return(defaultValue);
 }
Exemplo n.º 5
0
 public static string GetString(string key, string defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         return(PlayerPrefs.GetString(key));
     }
     return(defaultValue);
 }
Exemplo n.º 6
0
 public static bool GetBool(string key, bool defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         return(PlayerPrefs.GetInt(key) >= 1);
     }
     return(defaultValue);
 }
Exemplo n.º 7
0
 public static void SetDateTime(string key, DateTime value)
 {
     if (value.Kind == DateTimeKind.Local)
     {
         value = value.ToUniversalTime();
     }
     UserPrefs.SetLong(key, value.ToBinary());
 }
Exemplo n.º 8
0
        public static bool CheckHash(string originalKey, string value, string hashSuffix)
        {
            if (!StringUtils.HasText(value))
            {
                return(true);
            }
            string @string = UserPrefs.GetString(UserPrefs.CreateHashKey(originalKey), null);
            string a       = UserPrefs.CreateHashValue(value, hashSuffix);

            return(a == @string);
        }
Exemplo n.º 9
0
        public static float?SetFloatAndReturnPrevious(string key, float value)
        {
            float?result = null;

            if (UserPrefs.HasKey(key))
            {
                result = new float?(PlayerPrefs.GetFloat(key));
            }
            UserPrefs.SetFloat(key, value);
            return(result);
        }
Exemplo n.º 10
0
        public static string SetStringAndReturnPrevious(string key, string value)
        {
            string result = null;

            if (UserPrefs.HasKey(key))
            {
                result = PlayerPrefs.GetString(key);
            }
            UserPrefs.SetString(key, value);
            return(result);
        }
Exemplo n.º 11
0
        public static int?SetIntAndReturnPrevious(string key, int value)
        {
            int?result = null;

            if (UserPrefs.HasKey(key))
            {
                result = new int?(PlayerPrefs.GetInt(key));
            }
            UserPrefs.SetInt(key, value);
            return(result);
        }
Exemplo n.º 12
0
        public static bool?SetBoolAndReturnPrevious(string key, bool value)
        {
            bool?result = null;

            if (UserPrefs.HasKey(key))
            {
                result = new bool?(PlayerPrefs.GetInt(key) >= 1);
            }
            UserPrefs.SetBool(key, value);
            return(result);
        }
Exemplo n.º 13
0
        public static void SetXml <T>(string key, T obj)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            StringWriter  sw         = new StringWriter();

            serializer.Serialize(sw, obj);
            //Debug.LogError(sw.ToString());
            Debug.Log("Save Obj : " + key);
            string en = EncryptUtils.Base64Encrypt(sw.ToString());

            UserPrefs.SetString(key, en);
        }
Exemplo n.º 14
0
        public static List <string> GetCollectionAsList(string key, List <string> defaultCollection)
        {
            if (!UserPrefs.HasKey(key))
            {
                return(defaultCollection);
            }
            string @string = PlayerPrefs.GetString(key);

            if (@string == EmptyCollectionValue)
            {
                return(new List <string>(0));
            }
            return(StringUtils.CommaDelimitedListToStringList(@string));
        }
Exemplo n.º 15
0
        public static void SetCollection(string key, ICollection <string> collection)
        {
            string value;

            if (collection == null || collection.Count == 0)
            {
                value = EmptyCollectionValue;
            }
            else
            {
                value = StringUtils.CollectionToCommaDelimitedString <string>(collection);
            }
            UserPrefs.SetString(key, value);
        }
Exemplo n.º 16
0
 public static void SaveDelayed(float delaySecs)
 {
     if (UserPrefs.MainExecutor != null)
     {
         if (UserPrefs.SavePending)
         {
             return;
         }
         UserPrefs.MainExecutor.PostDelayed(new Action(UserPrefs.Save), (double)delaySecs);
         UserPrefs.SavePending = true;
     }
     else
     {
         UserPrefs.Save();
     }
 }
Exemplo n.º 17
0
        public static Queue <string> GetCollectionAsQueue(string key, Queue <string> defaultCollection)
        {
            if (!UserPrefs.HasKey(key))
            {
                return(defaultCollection);
            }
            string @string = PlayerPrefs.GetString(key);

            if (@string == EmptyCollectionValue)
            {
                return(new Queue <string>(0));
            }
            List <string> collection = StringUtils.CommaDelimitedListToStringList(@string);

            return(new Queue <string>(collection));
        }
Exemplo n.º 18
0
        public virtual void Init()
        {
            DateTime utcNow = DateTime.UtcNow;

            this.FirstStartTime = UserPrefs.GetDateTime("GameState.FirstStartDateTime", DateTime.MinValue);
            if (this.FirstStartTime == DateTime.MinValue)
            {
                this.FirstStartTime = utcNow;
                UserPrefs.SetDateTime("GameState.FirstStartDateTime", this.FirstStartTime);
                UserPrefs.Save();
                this.FirstStart = true;
            }
            this.StartTime = UserPrefs.GetDateTime("AppSession.StartTime", utcNow);
            this.PauseTime = UserPrefs.GetDateTime("AppSession.PauseTime", utcNow);
            this.SessionId = UserPrefs.GetInt("AppSession.SessionId", 0);
            this.AfterInit();
        }
Exemplo n.º 19
0
        public static T GetXml <T>(string key, T defaultT)
        {
            if (UserPrefs.HasKey(key))
            {
                string en = UserPrefs.GetString(key, "");
                if (en == "")
                {
                    return(defaultT);
                }

                string        de = EncryptUtils.Base64Decrypt(en);
                XmlSerializer ss = new XmlSerializer(typeof(T));
                StringReader  sr = new StringReader(de);
                return((T)ss.Deserialize(sr));
            }
            return(defaultT);
        }
Exemplo n.º 20
0
        protected virtual void CreateNewSession(DateTime toTime)
        {
            DateTime utcNow = DateTime.UtcNow;

            this.PreviousSessionDuration = toTime - this.StartTime;
            this.PauseDuration           = utcNow - this.PauseTime;
            if (this.PreviousSessionDuration.Milliseconds < 0)
            {
            }
            this.StartTime = utcNow;
            this.PauseTime = this.StartTime;
            this.SessionId++;
            this.FirstStart = false;
            UserPrefs.SetDateTime("AppSession.StartTime", this.StartTime);
            UserPrefs.SetDateTime("AppSession.PauseTime", this.PauseTime);
            UserPrefs.SetInt("AppSession.SessionId", this.SessionId);
            UserPrefs.SaveDelayed();
        }
Exemplo n.º 21
0
 public static JsonObject GetJson(string key, JsonObject defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         string @string = PlayerPrefs.GetString(key);
         try
         {
             JsonObject result = SimpleJson.SimpleJson.DeserializeObject <JsonObject> (@string);
             return(result);
         }
         catch
         {
             JsonObject result = defaultValue;
             return(result);
         }
         return(defaultValue);
     }
     return(defaultValue);
 }
Exemplo n.º 22
0
        public static long?SetLongAndReturnPrevious(string key, long value)
        {
            long?result = null;

            if (UserPrefs.HasKey(key))
            {
                string @string = PlayerPrefs.GetString(key);
                try
                {
                    result = new long?(long.Parse(@string, NumberStyles.Integer, NumberFormatInfo.InvariantInfo));
                }
                catch (FormatException)
                {
                }
                catch (OverflowException)
                {
                }
            }
            UserPrefs.SetLong(key, value);
            return(result);
        }
Exemplo n.º 23
0
        public static double?SetDoubleAndReturnPrevious(string key, double value)
        {
            double?result = null;

            if (UserPrefs.HasKey(key))
            {
                string @string = PlayerPrefs.GetString(key);
                try
                {
                    result = new double?(double.Parse(@string, NumberStyles.Float, NumberFormatInfo.InvariantInfo));
                }
                catch (FormatException)
                {
                }
                catch (OverflowException)
                {
                }
            }
            UserPrefs.SetDouble(key, value);
            return(result);
        }
Exemplo n.º 24
0
 public static long GetLong(string key, long defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         string @string = PlayerPrefs.GetString(key);
         try
         {
             long result = long.Parse(@string, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
             return(result);
         }
         catch (FormatException)
         {
             long result = defaultValue;
             return(result);
         }
         catch (OverflowException)
         {
             long result = defaultValue;
             return(result);
         }
         return(defaultValue);
     }
     return(defaultValue);
 }
Exemplo n.º 25
0
 public static double GetDouble(string key, double defaultValue)
 {
     if (UserPrefs.HasKey(key))
     {
         string @string = PlayerPrefs.GetString(key);
         try
         {
             double result = double.Parse(@string, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
             return(result);
         }
         catch (FormatException)
         {
             double result = defaultValue;
             return(result);
         }
         catch (OverflowException)
         {
             double result = defaultValue;
             return(result);
         }
         return(defaultValue);
     }
     return(defaultValue);
 }
Exemplo n.º 26
0
 public static DateTime GetDateTime(string key, DateTime defaultValue)
 {
     return(DateTime.FromBinary(UserPrefs.GetLong(key, defaultValue.ToBinary())));
 }
Exemplo n.º 27
0
 public static void RemoveHash(string key)
 {
     UserPrefs.Remove(UserPrefs.CreateHashKey(key));
 }
Exemplo n.º 28
0
 public static void SaveDelayed()
 {
     UserPrefs.SaveDelayed(1.2f);
 }
Exemplo n.º 29
0
        public static void SetHash(string originalKey, string value, string hashSuffix)
        {
            string value2 = UserPrefs.CreateHashValue(value, hashSuffix);

            UserPrefs.SetString(UserPrefs.CreateHashKey(originalKey), value2);
        }
Exemplo n.º 30
0
 public static void SetJson(string key, JsonObject value)
 {
     UserPrefs.SetString(key, (!(value != null)) ? null : value.ToString());
 }