Пример #1
0
            private void ReadValue()
            {
                var stringTry = PlayerPrefs.GetString(key, DefaultString);

                if (stringTry != DefaultString)
                {
                    prefType    = PrefsType.String;
                    stringValue = stringTry;
                    return;
                }

                var floatTry = PlayerPrefs.GetFloat(key, DefaultFloat);

                if (Math.Abs(floatTry - DefaultFloat) > 0.0000001f)
                {
                    prefType   = PrefsType.Float;
                    floatValue = floatTry;
                    return;
                }

                var intTry = PlayerPrefs.GetInt(key, DefaultInt);

                if (intTry != DefaultInt)
                {
                    prefType = PrefsType.Int;
                    intValue = intTry;
                    return;
                }
            }
Пример #2
0
            private void ReadValue()
            {
                float floatTry = PlayerPrefs.GetFloat(key, DEFAULT_FLOAT);

                if (Math.Abs(floatTry - DEFAULT_FLOAT) > 0.0000001f)
                {
                    prefType   = PrefsType.Float;
                    floatValue = floatTry;
                    return;
                }

                int intTry = PlayerPrefs.GetInt(key, DEFAULT_INT);

                if (intTry != DEFAULT_INT)
                {
                    prefType = PrefsType.Int;
                    intValue = intTry;
                    return;
                }

                string stringTry = PlayerPrefs.GetString(key, DEFAULT_STRING);

                if (stringTry != DEFAULT_STRING)
                {
                    prefType    = PrefsType.String;
                    stringValue = stringTry;
                    return;
                }
            }
Пример #3
0
        internal PrefsRecord(string newKey, float value)
        {
            key        = savedKey = newKey;
            floatValue = value;

            prefType = PrefsType.Float;
        }
Пример #4
0
        internal PrefsRecord(string newKey, int value)
        {
            key      = savedKey = newKey;
            intValue = value;

            prefType = PrefsType.Int;
        }
Пример #5
0
        internal PrefsRecord(string newKey, string value)
        {
            key         = savedKey = newKey;
            stringValue = value;

            prefType = PrefsType.String;
        }
Пример #6
0
            internal void Decrypt()
            {
                if (!Obscured)
                {
                    return;
                }
                if (!IsEditableObscuredValue())
                {
                    return;
                }

                bool success = true;

                switch (obscuredType)
                {
                case ObscuredPrefs.DataType.Int:
                    prefType = PrefsType.Int;
                    break;

                case ObscuredPrefs.DataType.String:
                    prefType = PrefsType.String;
                    break;

                case ObscuredPrefs.DataType.Float:
                    prefType = PrefsType.Float;
                    break;

                case ObscuredPrefs.DataType.UInt:
                case ObscuredPrefs.DataType.Double:
                case ObscuredPrefs.DataType.Long:
                case ObscuredPrefs.DataType.Bool:
                case ObscuredPrefs.DataType.ByteArray:
                case ObscuredPrefs.DataType.Vector2:
                case ObscuredPrefs.DataType.Vector3:
                case ObscuredPrefs.DataType.Quaternion:
                case ObscuredPrefs.DataType.Color:
                case ObscuredPrefs.DataType.Rect:
                    instance.ShowNotification(new GUIContent("Type " + obscuredType + " isn't supported"));
                    success = false;
                    break;

                case ObscuredPrefs.DataType.Unknown:
                    instance.ShowNotification(new GUIContent("Can't decrypt " + key));
                    success = false;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (success)
                {
                    Obscured     = false;
                    obscuredType = ObscuredPrefs.DataType.Unknown;
                    dirtyValue   = dirtyKey = true;
                }
            }
Пример #7
0
 private static string GetPrefsName(PrefsType type, bool isLua = true)
 {
     string typeName = type.ToString();
     if (isLua)
     {
         typeName = typeName + ".json";
     }
     return typeName;
 }
Пример #8
0
 public static bool GetLocalArchive(PrefsType type, out string value)
 {
     string prefsName = GetPrefsName(type);
     value = ReadFile.LoadFile(GetArchivePath(), prefsName);
     if (string.IsNullOrEmpty(value))
     {
         return false;
     }
     return true;
 }
Пример #9
0
            internal PrefsRecord(string newKey, string value, bool encrypted)
            {
                key         = savedKey = newKey;
                stringValue = value;

                prefType = PrefsType.String;

                if (encrypted)
                {
                    obscuredType = ObscuredPrefs.DataType.String;
                    Obscured     = true;
                }
            }
Пример #10
0
            internal PrefsRecord(string newKey, float value, bool encrypted)
            {
                key        = savedKey = newKey;
                floatValue = value;

                if (encrypted)
                {
                    prefType     = PrefsType.String;
                    obscuredType = ObscuredPrefs.DataType.Float;
                    Obscured     = true;
                }
                else
                {
                    prefType = PrefsType.Float;
                }
            }
Пример #11
0
        public PrefsValue(string key, T defaultValue, bool autoSave, PrefsType prefsType)
        {
            m_IsInitialized = true;

            m_Key          = key;
            m_Value        = defaultValue;
            m_DefaultValue = defaultValue;
            m_AutoSave     = autoSave;
            m_PrefsType    = prefsType;

            Type type = typeof(T);

            if (type == typeof(string))
            {
                m_ValueType = ValueType.String;
            }
            else if (type == typeof(float))
            {
                m_ValueType = ValueType.Float;
            }
            else if (type == typeof(bool))
            {
                m_ValueType = ValueType.Bool;
            }
            else if (type == typeof(int))
            {
                m_ValueType = ValueType.Int;
            }
            else if (type == typeof(Color))
            {
                m_ValueType = ValueType.Color;
            }
            else
            {
                m_ValueType = ValueType.Unknown;
                MDebug.LogError("Prefs", $"ValueItem not support value type({type})");
            }

            Load();
        }
Пример #12
0
            internal void Encrypt()
            {
                if (Obscured)
                {
                    return;
                }

                bool success = true;

                switch (prefType)
                {
                case PrefsType.Unknown:
                    success = false;
                    Debug.LogError(ActEditorGlobalStuff.LOG_PREFIX + "Can't encrypt pref of unknown type!");
                    break;

                case PrefsType.String:
                    obscuredType = ObscuredPrefs.DataType.String;
                    break;

                case PrefsType.Int:
                    obscuredType = ObscuredPrefs.DataType.Int;
                    break;

                case PrefsType.Float:
                    obscuredType = ObscuredPrefs.DataType.Float;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (success)
                {
                    prefType   = PrefsType.String;
                    Obscured   = true;
                    dirtyValue = dirtyKey = true;
                }
            }
Пример #13
0
 public static void SetLocalArchive(PrefsType type, string value)
 {
     string prefsName = GetPrefsName(type);
     WriteFile.CreateFile(GetArchivePath(), prefsName, value);
 }
Пример #14
0
 public static int GetPrefs(PrefsType type)
 {
     string prefsName = GetPrefsName(type, false);
     return PlayerPrefs.GetInt(prefsName, 0);
 }
Пример #15
0
 public static void SetPrefs(PrefsType type, int value)
 {
     string prefsName = GetPrefsName(type, false);
     PlayerPrefs.SetInt(prefsName, value);
 }