| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Helpers |
| | 5 | | { |
| | 6 | | public static class PlayerPrefsBridge |
| | 7 | | { |
| 1 | 8 | | private static readonly IPlayerPrefsProvider PROVIDER = Application.platform.Equals(RuntimePlatform.WebGLPlayer) |
| | 9 | | ? new PlayerPrefsProviderLocalStorage() |
| | 10 | | : new PlayerPrefsProviderDefault(); |
| | 11 | |
|
| | 12 | | public static int GetInt(string key) => |
| 0 | 13 | | PROVIDER.GetInt(key); |
| | 14 | |
|
| | 15 | | public static int GetInt(string key, int defaultValue) => |
| 365 | 16 | | PROVIDER.GetInt(key, defaultValue); |
| | 17 | |
|
| | 18 | | public static bool GetBool(string key, bool defaultValue) => |
| 4004 | 19 | | PROVIDER.GetBool(key, defaultValue); |
| | 20 | |
|
| | 21 | | public static void SetBool(string key, bool value) |
| | 22 | | { |
| 66 | 23 | | SetPlayerPref(() => PROVIDER.SetBool(key, value), key, "bool"); |
| 33 | 24 | | } |
| | 25 | |
|
| | 26 | | public static void SetInt(string key, int value) |
| | 27 | | { |
| 6 | 28 | | SetPlayerPref(() => PROVIDER.SetInt(key, value), key, "int"); |
| 3 | 29 | | } |
| | 30 | |
|
| | 31 | | public static bool HasKey(string key) => |
| 1092 | 32 | | PROVIDER.HasKey(key); |
| | 33 | |
|
| | 34 | | public static string GetString(string key, string defaultValue = null) => |
| 3276 | 35 | | PROVIDER.GetString(key, defaultValue); |
| | 36 | |
|
| | 37 | | public static void SetString(string key, string value) |
| | 38 | | { |
| 54 | 39 | | SetPlayerPref(() => PROVIDER.SetString(key, value), key, "string"); |
| 27 | 40 | | } |
| | 41 | |
|
| | 42 | | public static void Save() |
| | 43 | | { |
| 3 | 44 | | PROVIDER.Save(); |
| 3 | 45 | | } |
| | 46 | |
|
| | 47 | | public static float GetFloat(string key, float defaultValue = 0f) => |
| 6552 | 48 | | PROVIDER.GetFloat(key, defaultValue); |
| | 49 | |
|
| | 50 | | public static void SetFloat(string key, float value) |
| | 51 | | { |
| 108 | 52 | | SetPlayerPref(() => PROVIDER.SetFloat(key, value), key, "float"); |
| 54 | 53 | | } |
| | 54 | |
|
| | 55 | | private static void SetPlayerPref(Action setFunc, string key, string typeName) |
| | 56 | | { |
| 234 | 57 | | try { setFunc(); } |
| 0 | 58 | | catch (PlayerPrefsException e) { Debug.Log($"There was an issue setting {key} PlayerPrefs {typeName}!"); } |
| 117 | 59 | | } |
| | 60 | | } |
| | 61 | | } |