Esempio n. 1
0
    public static bool GetBool(string key, bool defaultValue = false)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetBool(GetCTUKey(key), defaultValue));
        }
        else
        {
            if (!HasKey(key))
            {
                return(defaultValue);
            }

            bool realbool = GetInt(key) == 1;
            //转换后保存到本地
            UPlayerPrefs.SetBool(GetCTUKey(key), realbool);
            return(realbool);
        }
#else
        if (!HasKey(key))
        {
            return(defaultValue);
        }

        return(GetInt(key) == 1);
#endif
    }
Esempio n. 2
0
 public static void SetDate(string key, DateTime date)
 {
     if (!string.IsNullOrEmpty(key))
     {
         UPlayerPrefs.SetString(key, date.ToString());
     }
 }
Esempio n. 3
0
    /// <summary>
    /// Removes key and its corresponding value from the preferences.
    /// </summary>
    public static void DeleteKey(string key)
    {
#if CONVERT
        bool uhaskey = UPlayerPrefs.HasKey(ConvertTittle + key);
        if (uhaskey)
        {
            UPlayerPrefs.DeleteKey(ConvertTittle + key);
        }
        else
        {
            string cKey = hashedKey(key);

            bool chaskey = PlayerPrefs.HasKey(cKey);
            if (chaskey)
            {
                PlayerPrefs.DeleteKey(cKey);
            }
        }
#else
        // Get hashed key
        string cKey = hashedKey(key);

        PlayerPrefs.DeleteKey(cKey);
#endif
    }
Esempio n. 4
0
    /// <summary>
    /// Returns true if key exists in the preferences.
    /// </summary>
    public static bool HasKey(string key)
    {
#if CONVERT
        bool uhaskey = UPlayerPrefs.HasKey(ConvertTittle + key);
        if (uhaskey)
        {
            return(uhaskey);
        }
        else
        {
            string cKey = hashedKey(key);

            bool chaskey = PlayerPrefs.HasKey(cKey);
            if (chaskey)
            {
                return(chaskey);
            }
        }
        return(false);
#else
        string cKey = hashedKey(key);

        return(PlayerPrefs.HasKey(cKey));
#endif
        // Get hashed key
    }
Esempio n. 5
0
    public static void SetDouble(string key, double value)
    {
#if CONVERT
        UPlayerPrefs.SetDouble(GetCTUKey(key), value);
#else
        PlayerPrefs.SetString(key, DoubleToString(value));
#endif
    }
Esempio n. 6
0
    public static void SetBool(string key, bool value)
    {
#if CONVERT
        UPlayerPrefs.SetBool(GetCTUKey(key), value);
#else
        SetInt(key, value ? 1 : 0);
#endif
    }
Esempio n. 7
0
    /// <summary>
    /// Sets the value of the preference identified by key.
    /// </summary>
    public static void SetFloat(string key, float val)
    {
#if CONVERT
        UPlayerPrefs.SetFloat(GetCTUKey(key), val);
#else
        SetString(key, val.ToString());
#endif
    }
Esempio n. 8
0
 public static void SetObject(string key, object obj)
 {
     if (!string.IsNullOrEmpty(key))
     {
         if (obj != null)
         {
             UPlayerPrefs.SetString(key, Newtonsoft.Json.JsonConvert.SerializeObject(obj));
         }
         else
         {
             UPlayerPrefs.SetString(key, "");
         }
     }
 }
Esempio n. 9
0
    public static T GetObject <T>(string key, T defVal) where T : new()
    {
        T obj = defVal;

        string objData = UPlayerPrefs.GetString(key, "");

        obj = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(objData);
        if (obj == null)
        {
            obj = defVal;
        }

        return(obj);
    }
Esempio n. 10
0
    /// <summary>
    /// Returns the value corresponding to key in the preference file if it exists.
    /// If it doesn't exist, it will return defaultValue.
    /// </summary>
    public static float GetFloat(string key, float defaultValue)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetFloat(GetCTUKey(key), defaultValue));
        }
        else
        {
            float realfloat = float.Parse(CGetString(key, defaultValue.ToString()));
            //转换后保存在本地
            UPlayerPrefs.SetFloat(GetCTUKey(key), realfloat);
            return(realfloat);
        }
#else
        return(float.Parse(GetString(key, defaultValue.ToString())));
#endif
    }
Esempio n. 11
0
    /// <summary>
    /// Returns the value corresponding to key in the preference file if it exists.
    /// If it doesn't exist, it will return defaultValue.
    /// </summary>
    public static long GetLong(string key, long defaultValue)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetLong(GetCTUKey(key), defaultValue));
        }
        else
        {
            long reallong = long.Parse(CGetString(key, defaultValue.ToString()));
            //转换后保存到本地
            UPlayerPrefs.SetLong(GetCTUKey(key), reallong);
            return(reallong);
        }
#else
        return(long.Parse(GetString(key, defaultValue.ToString())));
#endif
    }
Esempio n. 12
0
    public static double GetDouble(string key, double defaultValue)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetDouble(GetCTUKey(key), defaultValue));
        }
        else
        {
            string defaultVal = DoubleToString(defaultValue);
            double realdouble = StringToDouble(PlayerPrefs.GetString(key, defaultVal));
            //转换后保存本地
            UPlayerPrefs.SetDouble(GetCTUKey(key), realdouble);
            return(realdouble);
        }
#else
        string defaultVal = DoubleToString(defaultValue);
        return(StringToDouble(PlayerPrefs.GetString(key, defaultVal)));
#endif
    }
Esempio n. 13
0
    /// <summary>
    /// Sets the value of the preference identified by key.
    /// </summary>
    public static void SetString(string key, string val)
    {
#if CONVERT
        UPlayerPrefs.SetString(GetCTUKey(key), val);
#else
        // Get crypted key
        string cKey = hashedKey(key);

        string cryptedString = val;
        // If enabled use xor algo
        if (_useXor)
        {
            // Get crypt helper values
            int xor = computeXorOperand(key, cKey);
            int ad  = computePlusOperand(xor);

            // Compute crypted string
            cryptedString = "";
            foreach (char c in val)
            {
                char cryptedChar = (char)(((int)c + ad) ^ xor);
                cryptedString += cryptedChar;
            }
        }

        // If enabled use rijndael algo
        if (_useRijndael)
        {
            // Save
            string data = encrypt(cKey, cryptedString);
            if (data != null)
            {
                PlayerPrefs.SetString(cKey, data);
            }
        }
        else
        {
            PlayerPrefs.SetString(cKey, cryptedString);
        }
#endif
    }
Esempio n. 14
0
    /// <summary>
    /// Sets the value of the preference identified by key.
    /// </summary>
    public static void SetInt(string key, int val)
    {
#if CONVERT
        UPlayerPrefs.SetInt(GetCTUKey(key), val);
#else
        // Get crypted key
        string cKey = hashedKey(key);

        int cryptedInt = val;

        // If enabled use xor algo
        if (_useXor)
        {
            // Get crypt helper values
            int xor = computeXorOperand(key, cKey);
            int ad  = computePlusOperand(xor);

            // Compute crypted int
            cryptedInt = (val + ad) ^ xor;
        }

        // If enabled use rijndael algo
        if (_useRijndael)
        {
            // Save
            string data = encrypt(cKey, string.Empty + cryptedInt);

            if (data != null)
            {
                PlayerPrefs.SetString(cKey, data);
            }
        }
        else
        {
            PlayerPrefs.SetInt(cKey, cryptedInt);
        }
#endif
    }
Esempio n. 15
0
 public static void SetLong(string key, long val)
 {
     UPlayerPrefs.SetString(key, val.ToString());
 }
Esempio n. 16
0
 public static void Save()
 {
     UPlayerPrefs.SetObject("IPlayer", _CurrentPlayer);
 }
Esempio n. 17
0
 public static void Init()
 {
     _CurrentPlayer = UPlayerPrefs.GetObject <IPlayer>("IPlayer", null);
 }
Esempio n. 18
0
    /// <summary>
    /// Returns the value corresponding to key in the preference file if it exists.
    /// If it doesn't exist, it will return defaultValue.
    /// </summary>
    public static int GetInt(string key, int defaultValue)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetInt(GetCTUKey(key), defaultValue));
        }
        else
        {
            string cKey = hashedKey(key);

            // If the key doesn't exists, return defaultValue
            if (!PlayerPrefs.HasKey(cKey))
            {
                return(defaultValue);
            }
            else
            {
                int storedPref = defaultValue;
                if (_useRijndael)
                {
                    try
                    {
                        storedPref = int.Parse(decrypt(cKey));
                    }
                    catch (Exception ex)
                    {
                        BetaLog.Log.Exception(ex);
                    }
                }
                else
                {
                    storedPref = PlayerPrefs.GetInt(cKey);
                }

                // If xor algo enabled
                int realValue = storedPref;
                if (_useXor)
                {
                    // Get crypt helper values
                    int xor = computeXorOperand(key, cKey);
                    int ad  = computePlusOperand(xor);

                    // Compute real value
                    realValue = (xor ^ storedPref) - ad;
                }
                //转换后保存
                UPlayerPrefs.SetInt(GetCTUKey(key), realValue);
                return(realValue);
            }
        }
#else
        // Get crypted key
        string cKey = hashedKey(key);

        // If the key doesn't exists, return defaultValue
        if (!PlayerPrefs.HasKey(cKey))
        {
            return(defaultValue);
        }

        // Read storedPref
        int storedPref = defaultValue;
        if (_useRijndael)
        {
            try
            {
                storedPref = int.Parse(decrypt(cKey));
            }
            catch (Exception ex)
            {
                BetaLog.Log.Exception(ex);
            }
        }
        else
        {
            storedPref = PlayerPrefs.GetInt(cKey);
        }

        // If xor algo enabled
        int realValue = storedPref;
        if (_useXor)
        {
            // Get crypt helper values
            int xor = computeXorOperand(key, cKey);
            int ad  = computePlusOperand(xor);

            // Compute real value
            realValue = (xor ^ storedPref) - ad;
        }

        return(realValue);
#endif
    }
Esempio n. 19
0
    public static string GetString(string key, string defaultValue)
    {
#if CONVERT
        if (UPlayerPrefs.HasKey(GetCTUKey(key)))
        {
            return(UPlayerPrefs.GetString(GetCTUKey(key)));
        }
        else
        {
            // Get crypted key
            string cKey = hashedKey(key);

            // If the key doesn't exists, return defaultValue
            if (!PlayerPrefs.HasKey(cKey))
            {
                return(defaultValue);
            }

            // Read storedPref
            string storedPref;
            if (_useRijndael)
            {
                storedPref = decrypt(cKey);
            }
            else
            {
                storedPref = PlayerPrefs.GetString(cKey);
            }

            // XOR algo enabled?
            string realString = storedPref;
            if (_useXor)
            {
                // Get crypt helper values
                int xor = computeXorOperand(key, cKey);
                int ad  = computePlusOperand(xor);

                // Compute real value
                realString = "";
                foreach (char c in storedPref)
                {
                    char realChar = (char)((xor ^ c) - ad);
                    realString += realChar;
                }
            }
            //转换一下
            UPlayerPrefs.SetString(GetCTUKey(key), realString);
            return(realString);
        }
#else
        // Get crypted key
        string cKey = hashedKey(key);

        // If the key doesn't exists, return defaultValue
        if (!PlayerPrefs.HasKey(cKey))
        {
            return(defaultValue);
        }

        // Read storedPref
        string storedPref;
        if (_useRijndael)
        {
            storedPref = decrypt(cKey);
        }
        else
        {
            storedPref = PlayerPrefs.GetString(cKey);
        }

        // XOR algo enabled?
        string realString = storedPref;
        if (_useXor)
        {
            // Get crypt helper values
            int xor = computeXorOperand(key, cKey);
            int ad  = computePlusOperand(xor);

            // Compute real value
            realString = "";
            foreach (char c in storedPref)
            {
                char realChar = (char)((xor ^ c) - ad);
                realString += realChar;
            }
        }

        return(realString);
#endif
    }