| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL.SettingsControls |
| | 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 SettingsData.GeneralSettings currentGeneralSettings; |
| | 11 | | protected SettingsData.QualitySettings currentQualitySetting; |
| | 12 | | protected SettingsData.AudioSettings currentAudioSettings; |
| | 13 | |
|
| | 14 | | public virtual void Initialize() |
| | 15 | | { |
| 49 | 16 | | currentGeneralSettings = Settings.i.generalSettings; |
| 49 | 17 | | currentQualitySetting = Settings.i.qualitySettings; |
| 49 | 18 | | currentAudioSettings = Settings.i.audioSettings; |
| | 19 | |
|
| 49 | 20 | | Settings.i.OnGeneralSettingsChanged += OnGeneralSettingsChanged; |
| 49 | 21 | | Settings.i.OnQualitySettingsChanged += OnQualitySettingsChanged; |
| 49 | 22 | | Settings.i.OnAudioSettingsChanged += OnAudioSettingsChanged; |
| 49 | 23 | | Settings.i.OnResetAllSettings += OnResetSettingsControl; |
| 49 | 24 | | } |
| | 25 | |
|
| | 26 | | public virtual void OnDestroy() |
| | 27 | | { |
| 22 | 28 | | Settings.i.OnGeneralSettingsChanged -= OnGeneralSettingsChanged; |
| 22 | 29 | | Settings.i.OnQualitySettingsChanged -= OnQualitySettingsChanged; |
| 22 | 30 | | Settings.i.OnAudioSettingsChanged -= OnAudioSettingsChanged; |
| 22 | 31 | | Settings.i.OnResetAllSettings -= OnResetSettingsControl; |
| 22 | 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 | | { |
| 0 | 51 | | Settings.i.ApplyGeneralSettings(currentGeneralSettings); |
| 0 | 52 | | Settings.i.ApplyQualitySettings(currentQualitySetting); |
| 0 | 53 | | Settings.i.ApplyAudioSettings(currentAudioSettings); |
| 0 | 54 | | } |
| | 55 | |
|
| 0 | 56 | | private void OnGeneralSettingsChanged(SettingsData.GeneralSettings newGeneralSettings) { currentGeneralSettings |
| | 57 | |
|
| 0 | 58 | | private void OnQualitySettingsChanged(SettingsData.QualitySettings newQualitySettings) { currentQualitySetting = |
| | 59 | |
|
| 0 | 60 | | private void OnAudioSettingsChanged(SettingsData.AudioSettings newAudioSettings) { currentAudioSettings = newAud |
| | 61 | |
|
| | 62 | | private void OnResetSettingsControl() |
| | 63 | | { |
| 0 | 64 | | currentGeneralSettings = Settings.i.generalSettings; |
| 0 | 65 | | currentQualitySetting = Settings.i.qualitySettings; |
| 0 | 66 | | currentAudioSettings = Settings.i.audioSettings; |
| 0 | 67 | | } |
| | 68 | | } |
| | 69 | | } |