Example #1
0
    private void OnGUI()
    {
        // Delete toutes les préférence de l'éditeur. DANGEREUX
        //EditorPref.DeleteALL();

        int enumCount = System.Enum.GetNames(typeof(PrefsKey)).Length;

        for (int i = 0; i < enumCount; i++)
        {
            PrefsKey key       = (PrefsKey)i;
            bool     keyExists = EditorPrefs.HasKey(key.ToString());
            EditorGUI.BeginDisabledGroup(!keyExists);
            if (GUILayout.Button("Remove " + key.ToString()))
            {
                EditorPrefs.DeleteKey(key.ToString());
                GUI.FocusControl("");
            }
            EditorGUI.EndDisabledGroup();
        }

        m_Bool = EditorPrefs.GetBool(PrefsKey.Bool.ToString(), true);

        EditorGUI.BeginChangeCheck();
        m_Bool = EditorGUILayout.Toggle("bool", m_Bool);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetBool(PrefsKey.Bool.ToString(), m_Bool);
        }

        m_Int = EditorPrefs.GetInt(PrefsKey.Int.ToString(), -1);
        EditorGUI.BeginChangeCheck();
        m_Int = EditorGUILayout.IntField("INT", m_Int);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetInt(PrefsKey.Int.ToString(), m_Int);
        }

        m_Float = EditorPrefs.GetFloat(PrefsKey.Float.ToString(), 10f);
        EditorGUI.BeginChangeCheck();
        m_Float = EditorGUILayout.FloatField("Flaot", m_Float);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetFloat(PrefsKey.Float.ToString(), m_Float);
        }

        m_string = EditorPrefs.GetString(PrefsKey.String.ToString(), "Default");
        EditorGUI.BeginChangeCheck();
        m_string = EditorGUILayout.TextField("String", m_string);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetString(PrefsKey.String.ToString(), m_string);
        }
    }
Example #2
0
        public void SetFloat(PrefsKey prefsKey, float value)
        {
            string keyToStr = prefsKey.ToString();

            PlayerPrefs.SetFloat(keyToStr, value);
            SaveEncryption(keyToStr, "float", Mathf.Floor(value * 1000).ToString());
        }
Example #3
0
        public void SetInt(PrefsKey prefsKey, int value)
        {
            string keyToStr = prefsKey.ToString();

            PlayerPrefs.SetInt(keyToStr.ToString(), value);
            SaveEncryption(keyToStr, "int", value.ToString());
        }
Example #4
0
        public void SetString(PrefsKey prefsKey, string value)
        {
            string keyToStr = prefsKey.ToString();

            PlayerPrefs.SetString(keyToStr, value);
            SaveEncryption(keyToStr, "string", value);
        }
Example #5
0
        public void DeleteKey(PrefsKey prefsKey)
        {
            string keyToStr = prefsKey.ToString();

            PlayerPrefs.DeleteKey(keyToStr);
            PlayerPrefs.DeleteKey(keyToStr + "_encryption_check");
            PlayerPrefs.DeleteKey(keyToStr + "_used_key");
        }
Example #6
0
        public string GetString(PrefsKey prefsKey, string defaultValue)
        {
            string keyToStr = prefsKey.ToString();
            string value    = PlayerPrefs.GetString(keyToStr);

            if (!CheckEncryption(keyToStr, "string", value))
            {
                return(defaultValue);
            }
            return(value);
        }
Example #7
0
        public int GetInt(PrefsKey prefsKey, int defaultValue)
        {
            string keyToStr = prefsKey.ToString();
            int    value    = PlayerPrefs.GetInt(keyToStr);

            if (!CheckEncryption(keyToStr, "int", value.ToString()))
            {
                return(defaultValue);
            }
            return(value);
        }
Example #8
0
        public float GetFloat(PrefsKey prefsKey, float defaultValue)
        {
            string keyToStr = prefsKey.ToString();
            float  value    = PlayerPrefs.GetFloat(keyToStr);

            if (!CheckEncryption(keyToStr, "float", Mathf.Floor(value * 1000).ToString()))
            {
                return(defaultValue);
            }
            return(value);
        }
Example #9
0
        public static bool GetKeyValue(PrefsKey prefsKey, out string value, out bool json)
        {
            string propertyName;
            string prefsManager;
            string type;

            value = "";
            json  = false;

            if (!ParseKeyString(prefsKey.ToString(), out propertyName, out type, out prefsManager))
            {
                return(false);
            }

            IPrefsManager manager = GetManager(prefsManager);

            if (manager == null)
            {
                return(false);
            }

            switch (type)
            {
            case "Int":
            case "int":
                value = manager.GetInt(prefsKey, 0).ToString();
                break;

            case "bool":
            case "Bool":
                value = manager.GetInt(prefsKey, 0) == 1 ? "true" : "false";
                break;

            case "Float":
            case "float":
                value = manager.GetFloat(prefsKey, 0f).ToString();
                break;

            case "String":
            case "string":
                value = manager.Get(prefsKey, "");
                break;

            default:
                json = true;
                goto case "string";
            }

            return(true);
        }
Example #10
0
 public float GetFloat(PrefsKey prefsKey, float defaultValue)
 {
     return(PlayerPrefs.GetFloat(prefsKey.ToString(), defaultValue));
 }
Example #11
0
        public bool HasKey(PrefsKey key)
        {
            string keyToStr = key.ToString();

            return(PlayerPrefs.HasKey(keyToStr));
        }
Example #12
0
 public void SetString(PrefsKey prefsKey, string value)
 {
     PlayerPrefs.SetString(prefsKey.ToString(), value);
 }
Example #13
0
 public void SetInt(PrefsKey prefsKey, int value)
 {
     PlayerPrefs.SetInt(prefsKey.ToString(), value);
 }
Example #14
0
 public void SetFloat(PrefsKey prefsKey, float value)
 {
     PlayerPrefs.SetFloat(prefsKey.ToString(), value);
 }
Example #15
0
 public string GetString(PrefsKey prefsKey, string defaultValue)
 {
     return(PlayerPrefs.GetString(prefsKey.ToString(), defaultValue));
 }
Example #16
0
 public string GetString(PrefsKey prefsKey)
 {
     return(PlayerPrefs.GetString(prefsKey.ToString()));
 }
Example #17
0
 public int GetInt(PrefsKey prefsKey, int defaultValue)
 {
     return(PlayerPrefs.GetInt(prefsKey.ToString(), defaultValue));
 }
Example #18
0
 public int GetInt(PrefsKey prefsKey)
 {
     return(PlayerPrefs.GetInt(prefsKey.ToString()));
 }
Example #19
0
 public float GetFloat(PrefsKey prefsKey)
 {
     return(PlayerPrefs.GetFloat(prefsKey.ToString()));
 }
Example #20
0
 public void DeleteKey(PrefsKey key)
 {
     PlayerPrefs.DeleteKey(key.ToString());
 }