using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using KairoEngine.Core; using KairoEngine.Core.ConfigOptions; using KairoEngine.UI.Tooltips; using Sirenix.OdinInspector; using TMPro; namespace KairoEngine.UI.ConfigOptions { [HideMonoScript] public class CheckboxConfigOptionUI : MonoBehaviour { public TextMeshProUGUI titleText; public TooltipTrigger tooltipTrigger; public Toggle checkbox; [ReadOnly] public ConfigOptionBase configOption; public void OnEnable() { checkbox.onValueChanged.AddListener(delegate {OnChange(); }); } void OnDisable() { checkbox.onValueChanged.RemoveListener(delegate {OnChange(); }); } public void Setup(ConfigOptionBase configOption) { this.configOption = configOption; var uiData = configOption.GetUiData(); titleText.text = uiData.name; //tooltipTrigger.header = uiData.name; tooltipTrigger.content = uiData.description; checkbox.isOn = uiData.checkboxData.currentValue; } public void OnChange() { ApplyConfig(); } private void ApplyConfig() { if(configOption == null) return; ConfigOptionData data = new ConfigOptionData("", "", checkbox.isOn ? 1 : 0, 0f); configOption.SetValue(data, false); } private void SaveConfig() { if(configOption == null) return; ConfigOptionData data = new ConfigOptionData("", "", checkbox.isOn ? 1 : 0, 0f); configOption.SetValue(data, true); } } }