| | 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 | |
|
| | 13 | | public virtual void Initialize() |
| | 14 | | { |
| 38 | 15 | | currentGeneralSettings = Settings.i.generalSettings; |
| 38 | 16 | | currentQualitySetting = Settings.i.qualitySettings; |
| | 17 | |
|
| 38 | 18 | | Settings.i.OnGeneralSettingsChanged += OnGeneralSettingsChanged; |
| 38 | 19 | | Settings.i.OnQualitySettingsChanged += OnQualitySettingsChanged; |
| 38 | 20 | | Settings.i.OnResetAllSettings += OnResetSettingsControl; |
| 38 | 21 | | } |
| | 22 | |
|
| | 23 | | public virtual void OnDestroy() |
| | 24 | | { |
| 17 | 25 | | Settings.i.OnGeneralSettingsChanged -= OnGeneralSettingsChanged; |
| 17 | 26 | | Settings.i.OnQualitySettingsChanged -= OnQualitySettingsChanged; |
| 17 | 27 | | Settings.i.OnResetAllSettings -= OnResetSettingsControl; |
| 17 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// It should return the stored value of the control. |
| | 32 | | /// </summary> |
| | 33 | | /// <returns>It can be a bool (for toggle controls), a float (for slider controls) or an int (for spin-box contr |
| 0 | 34 | | public virtual object GetStoredValue() { return null; } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// All the needed logic to applying the setting and storing the current value. |
| | 38 | | /// </summary> |
| | 39 | | /// <param name="newValue">Value of the new state. It can be a bool (for toggle controls), a float (for slider c |
| 0 | 40 | | public virtual void UpdateSetting(object newValue) { } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Applies the current control state into the Settings class. |
| | 44 | | /// </summary> |
| | 45 | | public virtual void ApplySettings() |
| | 46 | | { |
| 0 | 47 | | Settings.i.ApplyGeneralSettings(currentGeneralSettings); |
| 0 | 48 | | Settings.i.ApplyQualitySettings(currentQualitySetting); |
| 0 | 49 | | } |
| | 50 | |
|
| 0 | 51 | | private void OnGeneralSettingsChanged(SettingsData.GeneralSettings newGeneralSettings) { currentGeneralSettings |
| | 52 | |
|
| 0 | 53 | | private void OnQualitySettingsChanged(SettingsData.QualitySettings newQualitySettings) { currentQualitySetting = |
| | 54 | |
|
| | 55 | | private void OnResetSettingsControl() |
| | 56 | | { |
| 0 | 57 | | currentGeneralSettings = Settings.i.generalSettings; |
| 0 | 58 | | currentQualitySetting = Settings.i.qualitySettings; |
| 0 | 59 | | } |
| | 60 | | } |
| | 61 | | } |