| | 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 | | { |
| 60 | 16 | | if (Settings.i == null) |
| 0 | 17 | | Settings.CreateSharedInstance(new DefaultSettingsFactory()); |
| | 18 | |
|
| 60 | 19 | | currentGeneralSettings = Settings.i.generalSettings.Data; |
| 60 | 20 | | currentQualitySetting = Settings.i.qualitySettings.Data; |
| 60 | 21 | | currentAudioSettings = Settings.i.audioSettings.Data; |
| | 22 | |
|
| 60 | 23 | | Settings.i.generalSettings.OnChanged += OnGeneralSettingsChanged; |
| 60 | 24 | | Settings.i.qualitySettings.OnChanged += OnQualitySettingsChanged; |
| 60 | 25 | | Settings.i.audioSettings.OnChanged += OnAudioSettingsChanged; |
| 60 | 26 | | Settings.i.OnResetAllSettings += OnResetSettingsControl; |
| 60 | 27 | | } |
| | 28 | |
|
| | 29 | | public virtual void OnDestroy() |
| | 30 | | { |
| 0 | 31 | | Settings.i.generalSettings.OnChanged -= OnGeneralSettingsChanged; |
| 0 | 32 | | Settings.i.qualitySettings.OnChanged -= OnQualitySettingsChanged; |
| 0 | 33 | | Settings.i.audioSettings.OnChanged -= OnAudioSettingsChanged; |
| 0 | 34 | | Settings.i.OnResetAllSettings -= OnResetSettingsControl; |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// It should return the stored value of the control. |
| | 39 | | /// </summary> |
| | 40 | | /// <returns>It can be a bool (for toggle controls), a float (for slider controls) or an int (for spin-box contr |
| 0 | 41 | | public virtual object GetStoredValue() { return null; } |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// All the needed logic to applying the setting and storing the current value. |
| | 45 | | /// </summary> |
| | 46 | | /// <param name="newValue">Value of the new state. It can be a bool (for toggle controls), a float (for slider c |
| 0 | 47 | | public virtual void UpdateSetting(object newValue) { } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Applies the current control state into the Settings class. |
| | 51 | | /// </summary> |
| | 52 | | public virtual void ApplySettings() |
| | 53 | | { |
| 8 | 54 | | Settings.i.generalSettings.Apply(currentGeneralSettings); |
| 8 | 55 | | Settings.i.qualitySettings.Apply(currentQualitySetting); |
| 8 | 56 | | Settings.i.audioSettings.Apply(currentAudioSettings); |
| 8 | 57 | | } |
| | 58 | |
|
| 88 | 59 | | private void OnGeneralSettingsChanged(GeneralSettings newGeneralSettings) { currentGeneralSettings = newGeneralS |
| | 60 | |
|
| 0 | 61 | | private void OnQualitySettingsChanged(QualitySettings newQualitySettings) { currentQualitySetting = newQualitySe |
| | 62 | |
|
| 0 | 63 | | private void OnAudioSettingsChanged(AudioSettings newAudioSettings) { currentAudioSettings = newAudioSettings; } |
| | 64 | |
|
| | 65 | | protected virtual void OnResetSettingsControl() |
| | 66 | | { |
| 0 | 67 | | currentGeneralSettings = Settings.i.generalSettings.Data; |
| 0 | 68 | | currentQualitySetting = Settings.i.qualitySettings.Data; |
| 0 | 69 | | currentAudioSettings = Settings.i.audioSettings.Data; |
| 0 | 70 | | } |
| | 71 | | } |
| | 72 | | } |