| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL.SettingsCommon.SettingsControllers.BaseControllers |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// This controller is in charge of manage all the logic related to a SETTING CONTROL. |
| | 7 | | /// </summary> |
| | 8 | | public class SettingsControlController : ScriptableObject |
| | 9 | | { |
| | 10 | | protected GeneralSettings currentGeneralSettings; |
| | 11 | | protected QualitySettings currentQualitySetting; |
| | 12 | | protected AudioSettings currentAudioSettings; |
| | 13 | |
|
| | 14 | | public virtual void Initialize() |
| | 15 | | { |
| 59 | 16 | | currentGeneralSettings = Settings.i.generalSettings.Data; |
| 59 | 17 | | currentQualitySetting = Settings.i.qualitySettings.Data; |
| 59 | 18 | | currentAudioSettings = Settings.i.audioSettings.Data; |
| | 19 | |
|
| 59 | 20 | | Settings.i.generalSettings.OnChanged += OnGeneralSettingsChanged; |
| 59 | 21 | | Settings.i.qualitySettings.OnChanged += OnQualitySettingsChanged; |
| 59 | 22 | | Settings.i.audioSettings.OnChanged += OnAudioSettingsChanged; |
| 59 | 23 | | Settings.i.OnResetAllSettings += OnResetSettingsControl; |
| 59 | 24 | | } |
| | 25 | |
|
| | 26 | | public virtual void OnDestroy() |
| | 27 | | { |
| 0 | 28 | | Settings.i.generalSettings.OnChanged -= OnGeneralSettingsChanged; |
| 0 | 29 | | Settings.i.qualitySettings.OnChanged -= OnQualitySettingsChanged; |
| 0 | 30 | | Settings.i.audioSettings.OnChanged -= OnAudioSettingsChanged; |
| 0 | 31 | | Settings.i.OnResetAllSettings -= OnResetSettingsControl; |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// It should return the stored value of the control. |
| | 36 | | /// </summary> |
| | 37 | | /// <returns>It can be a bool (for toggle controls), a float (for slider controls) or an int (for spin-box contr |
| 0 | 38 | | public virtual object GetStoredValue() { return null; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// All the needed logic to applying the setting and storing the current value. |
| | 42 | | /// </summary> |
| | 43 | | /// <param name="newValue">Value of the new state. It can be a bool (for toggle controls), a float (for slider c |
| 0 | 44 | | public virtual void UpdateSetting(object newValue) { } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Applies the current control state into the Settings class. |
| | 48 | | /// </summary> |
| | 49 | | public virtual void ApplySettings() |
| | 50 | | { |
| 11 | 51 | | Settings.i.generalSettings.Apply(currentGeneralSettings); |
| 11 | 52 | | Settings.i.qualitySettings.Apply(currentQualitySetting); |
| 11 | 53 | | Settings.i.audioSettings.Apply(currentAudioSettings); |
| 11 | 54 | | } |
| | 55 | |
|
| 100 | 56 | | private void OnGeneralSettingsChanged(GeneralSettings newGeneralSettings) { currentGeneralSettings = newGeneralS |
| | 57 | |
|
| 0 | 58 | | private void OnQualitySettingsChanged(QualitySettings newQualitySettings) { currentQualitySetting = newQualitySe |
| | 59 | |
|
| 0 | 60 | | private void OnAudioSettingsChanged(AudioSettings newAudioSettings) { currentAudioSettings = newAudioSettings; } |
| | 61 | |
|
| | 62 | | protected virtual void OnResetSettingsControl() |
| | 63 | | { |
| 0 | 64 | | currentGeneralSettings = Settings.i.generalSettings.Data; |
| 0 | 65 | | currentQualitySetting = Settings.i.qualitySettings.Data; |
| 0 | 66 | | currentAudioSettings = Settings.i.audioSettings.Data; |
| 0 | 67 | | } |
| | 68 | | } |
| | 69 | | } |