123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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 DropdownConfigOptionUI : MonoBehaviour
- {
- public TextMeshProUGUI titleText;
- public TooltipTrigger tooltipTrigger;
- public TMP_Dropdown dropdown;
- [ReadOnly] public ConfigOptionBase configOption;
- public void OnEnable()
- {
- dropdown.onValueChanged.AddListener(delegate {OnChange(); });
- }
- void OnDisable()
- {
- dropdown.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;
- var options = new List<TMP_Dropdown.OptionData>();
- for (int i = 0; i < uiData.dropdownData.options.Count; i++)
- {
- options.Add(new TMP_Dropdown.OptionData( uiData.dropdownData.options[i]));
- }
- dropdown.AddOptions(options);
- dropdown.value = uiData.dropdownData.currentValue;
- }
- public void OnChange()
- {
- ApplyConfig();
- }
- private void ApplyConfig()
- {
- if(configOption == null) return;
- ConfigOptionData data = new ConfigOptionData("", "", dropdown.value, 0f);
- configOption.SetValue(data, false);
- }
- private void SaveConfig()
- {
- if(configOption == null) return;
- ConfigOptionData data = new ConfigOptionData("", "", dropdown.value, 0f);
- configOption.SetValue(data, true);
- }
- }
- }
|