| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.SettingsCommon |
| | 5 | | { |
| | 6 | | public class PlayerPrefsQualitySettingsRepository : ISettingsRepository<QualitySettings> |
| | 7 | | { |
| | 8 | | private const string DISPLAY_NAME = "displayName"; |
| | 9 | | private const string BLOOM = "bloom"; |
| | 10 | | private const string FPS_CAP = "fpsCap"; |
| | 11 | | private const string SOFT_SHADOWS = "softShadows"; |
| | 12 | | private const string ENABLE_DETAIL_OBJECT_CULLING = "enableDetailObjectCulling"; |
| | 13 | | private const string SHADOWS = "shadows"; |
| | 14 | | private const string RENDER_SCALE = "renderScale"; |
| | 15 | | private const string SHADOW_DISTANCE = "shadowDistance"; |
| | 16 | | private const string CAMERA_DRAW_DISTANCE = "cameraDrawDistance"; |
| | 17 | | private const string DETAIL_OBJECT_CULLING_LIMIT = "detailObjectCullingLimit"; |
| | 18 | | private const string ANTI_ALIASING = "antiAliasing"; |
| | 19 | | private const string BASE_RESOLUTION = "baseResolution"; |
| | 20 | | private const string SHADOW_RESOLUTION = "shadowResolution"; |
| | 21 | | private const string SSAO_QUALITY = "ssaoQuality"; |
| | 22 | | private const string MAX_HQ_AVATARS = "maxHQAvatars"; |
| | 23 | | private const string REFLECTION_RESOLUTION = "reflectionResolution"; |
| | 24 | |
|
| | 25 | | private readonly IPlayerPrefsSettingsByKey settingsByKey; |
| | 26 | | private readonly QualitySettings defaultSettings; |
| | 27 | | private QualitySettings currentSettings; |
| | 28 | |
|
| | 29 | | public event Action<QualitySettings> OnChanged; |
| | 30 | |
|
| 640 | 31 | | public PlayerPrefsQualitySettingsRepository( |
| | 32 | | IPlayerPrefsSettingsByKey settingsByKey, |
| | 33 | | QualitySettings defaultSettings) |
| | 34 | | { |
| 640 | 35 | | this.settingsByKey = settingsByKey; |
| 640 | 36 | | this.defaultSettings = defaultSettings; |
| 640 | 37 | | currentSettings = Load(); |
| 640 | 38 | | } |
| | 39 | |
|
| 59 | 40 | | public QualitySettings Data => currentSettings; |
| | 41 | |
|
| | 42 | | public void Apply(QualitySettings settings) |
| | 43 | | { |
| 37 | 44 | | if (currentSettings.Equals(settings)) |
| 36 | 45 | | return; |
| 1 | 46 | | currentSettings = settings; |
| 1 | 47 | | OnChanged?.Invoke(currentSettings); |
| 0 | 48 | | } |
| | 49 | |
|
| 50 | 50 | | public void Reset() { Apply(defaultSettings); } |
| | 51 | |
|
| | 52 | | public void Save() |
| | 53 | | { |
| 1 | 54 | | settingsByKey.SetString(DISPLAY_NAME, currentSettings.displayName); |
| 1 | 55 | | settingsByKey.SetBool(BLOOM, currentSettings.bloom); |
| 1 | 56 | | settingsByKey.SetBool(FPS_CAP, currentSettings.fpsCap); |
| 1 | 57 | | settingsByKey.SetBool(SOFT_SHADOWS, currentSettings.softShadows); |
| 1 | 58 | | settingsByKey.SetBool(ENABLE_DETAIL_OBJECT_CULLING, currentSettings.enableDetailObjectCulling); |
| 1 | 59 | | settingsByKey.SetBool(SHADOWS, currentSettings.shadows); |
| 1 | 60 | | settingsByKey.SetFloat(RENDER_SCALE, currentSettings.renderScale); |
| 1 | 61 | | settingsByKey.SetFloat(SHADOW_DISTANCE, currentSettings.shadowDistance); |
| 1 | 62 | | settingsByKey.SetFloat(CAMERA_DRAW_DISTANCE, currentSettings.cameraDrawDistance); |
| 1 | 63 | | settingsByKey.SetFloat(DETAIL_OBJECT_CULLING_LIMIT, currentSettings.detailObjectCullingLimit); |
| 1 | 64 | | settingsByKey.SetEnum(ANTI_ALIASING, currentSettings.antiAliasing); |
| 1 | 65 | | settingsByKey.SetEnum(BASE_RESOLUTION, currentSettings.baseResolution); |
| 1 | 66 | | settingsByKey.SetEnum(SHADOW_RESOLUTION, currentSettings.shadowResolution); |
| 1 | 67 | | settingsByKey.SetEnum(SSAO_QUALITY, currentSettings.ssaoQuality); |
| 1 | 68 | | settingsByKey.SetInt(MAX_HQ_AVATARS, currentSettings.maxHQAvatars); |
| 1 | 69 | | settingsByKey.SetEnum(REFLECTION_RESOLUTION, currentSettings.reflectionResolution); |
| 1 | 70 | | } |
| | 71 | |
|
| 59 | 72 | | public bool HasAnyData() => !Data.Equals(defaultSettings); |
| | 73 | |
|
| | 74 | | private QualitySettings Load() |
| | 75 | | { |
| 640 | 76 | | var settings = defaultSettings; |
| | 77 | |
|
| | 78 | | try |
| | 79 | | { |
| 640 | 80 | | settings.displayName = settingsByKey.GetString(DISPLAY_NAME, defaultSettings.displayName); |
| 640 | 81 | | settings.bloom = settingsByKey.GetBool(BLOOM, defaultSettings.bloom); |
| 640 | 82 | | settings.fpsCap = settingsByKey.GetBool(FPS_CAP, defaultSettings.fpsCap); |
| 640 | 83 | | settings.softShadows = settingsByKey.GetBool(SOFT_SHADOWS, defaultSettings.softShadows); |
| 640 | 84 | | settings.enableDetailObjectCulling = settingsByKey.GetBool(ENABLE_DETAIL_OBJECT_CULLING, defaultSettings |
| 640 | 85 | | settings.shadows = settingsByKey.GetBool(SHADOWS, defaultSettings.shadows); |
| 640 | 86 | | settings.renderScale = settingsByKey.GetFloat(RENDER_SCALE, defaultSettings.renderScale); |
| 640 | 87 | | settings.shadowDistance = settingsByKey.GetFloat(SHADOW_DISTANCE, defaultSettings.shadowDistance); |
| 640 | 88 | | settings.cameraDrawDistance = settingsByKey.GetFloat(CAMERA_DRAW_DISTANCE, defaultSettings.cameraDrawDis |
| 640 | 89 | | settings.detailObjectCullingLimit = settingsByKey.GetFloat(DETAIL_OBJECT_CULLING_LIMIT, defaultSettings. |
| 640 | 90 | | settings.antiAliasing = settingsByKey.GetEnum(ANTI_ALIASING, defaultSettings.antiAliasing); |
| 640 | 91 | | settings.baseResolution = settingsByKey.GetEnum(BASE_RESOLUTION, defaultSettings.baseResolution); |
| 640 | 92 | | settings.shadowResolution = settingsByKey.GetEnum(SHADOW_RESOLUTION, defaultSettings.shadowResolution); |
| 640 | 93 | | settings.ssaoQuality = settingsByKey.GetEnum(SSAO_QUALITY, defaultSettings.ssaoQuality); |
| 640 | 94 | | settings.maxHQAvatars = settingsByKey.GetInt(MAX_HQ_AVATARS, defaultSettings.maxHQAvatars); |
| 640 | 95 | | settings.reflectionResolution = settingsByKey.GetEnum(REFLECTION_RESOLUTION, defaultSettings.reflectionR |
| 640 | 96 | | } |
| | 97 | | catch (Exception e) |
| | 98 | | { |
| 0 | 99 | | Debug.LogException(e); |
| 0 | 100 | | } |
| | 101 | |
|
| 640 | 102 | | return settings; |
| | 103 | | } |
| | 104 | | } |
| | 105 | | } |