| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace DCL.SettingsPanelHUD.Controls |
| | 6 | | { |
| | 7 | | public class DropdownItemColorSwap : MonoBehaviour |
| | 8 | | { |
| | 9 | | [SerializeField] private Toggle toggle; |
| | 10 | | [SerializeField] private TextMeshProUGUI targetText; |
| | 11 | | [SerializeField] private Image targetBackground; |
| | 12 | | [SerializeField] private Color textOn; |
| | 13 | | [SerializeField] private Color textOff; |
| | 14 | | [SerializeField] private Color bgOn; |
| | 15 | | [SerializeField] private Color bgOff; |
| | 16 | |
|
| | 17 | | private void OnEnable() |
| | 18 | | { |
| 0 | 19 | | toggle.onValueChanged.AddListener(OnValueChanged); |
| 0 | 20 | | OnValueChanged(toggle.isOn); |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | private void OnDisable() |
| | 24 | | { |
| 0 | 25 | | toggle.onValueChanged.RemoveListener(OnValueChanged); |
| 0 | 26 | | } |
| | 27 | |
|
| | 28 | | private void OnValueChanged(bool value) |
| | 29 | | { |
| 0 | 30 | | targetText.color = value ? textOn : textOff; |
| 0 | 31 | | targetBackground.color = value ? bgOn : bgOff; |
| 0 | 32 | | } |
| | 33 | | } |
| | 34 | | } |