| | 1 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace DCL.SettingsPanelHUD.Controls |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// MonoBehaviour that represents the view of a TOGGLE type CONTROL. |
| | 9 | | /// </summary> |
| | 10 | | public class ToggleSettingsControlView : SettingsControlView |
| | 11 | | { |
| | 12 | | [SerializeField] private Toggle toggle; |
| | 13 | |
|
| 0 | 14 | | public Toggle toggleControl { get => toggle; } |
| | 15 | |
|
| | 16 | | private ToggleSettingsControlController toggleController; |
| | 17 | |
|
| | 18 | | public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon |
| | 19 | | { |
| 11 | 20 | | toggleController = (ToggleSettingsControlController)settingsControlController; |
| | 21 | |
|
| 11 | 22 | | base.Initialize(controlConfig, toggleController); |
| 11 | 23 | | toggleController.UpdateSetting(toggle.isOn); |
| | 24 | |
|
| 11 | 25 | | toggle.onValueChanged.AddListener(isOn => |
| | 26 | | { |
| 0 | 27 | | ApplySetting(isOn); |
| 0 | 28 | | }); |
| 11 | 29 | | } |
| | 30 | |
|
| | 31 | | public override void RefreshControl() |
| | 32 | | { |
| 11 | 33 | | base.RefreshControl(); |
| | 34 | |
|
| 11 | 35 | | bool newValue = (bool)toggleController.GetStoredValue(); |
| 11 | 36 | | if (toggle.isOn != newValue) |
| 2 | 37 | | toggle.isOn = newValue; |
| 11 | 38 | | } |
| | 39 | | } |
| | 40 | | } |