| | 1 | | using DCL.Components; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using TMPro; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public class SmartItemOptionsParameter : SmartItemUIParameterAdapter |
| | 9 | | { |
| | 10 | | public TMP_Dropdown dropDown; |
| | 11 | |
|
| 0 | 12 | | private void Start() { dropDown.onValueChanged.AddListener(OnValueChange); } |
| | 13 | |
|
| | 14 | | public override void SetInfo() |
| | 15 | | { |
| 0 | 16 | | base.SetInfo(); |
| | 17 | |
|
| 0 | 18 | | dropDown.options = new List<TMP_Dropdown.OptionData>(); |
| | 19 | |
|
| 0 | 20 | | List<string> optionsLabelList = new List<string>(); |
| 0 | 21 | | foreach (SmartItemParameter.OptionsParameter options in currentParameter.options) |
| | 22 | | { |
| 0 | 23 | | optionsLabelList.Add(options.label); |
| | 24 | | } |
| | 25 | |
|
| 0 | 26 | | dropDown.AddOptions(optionsLabelList); |
| | 27 | |
|
| 0 | 28 | | string value = (string) GetParameterValue(); |
| | 29 | |
|
| 0 | 30 | | for (int i = 0; i < currentParameter.options.Length; i++) |
| | 31 | | { |
| 0 | 32 | | if (currentParameter.options[i].value == value) |
| 0 | 33 | | dropDown.SetValueWithoutNotify(i); |
| | 34 | | } |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | private void OnValueChange(int currentIndex) |
| | 38 | | { |
| 0 | 39 | | foreach (SmartItemParameter.OptionsParameter options in currentParameter.options) |
| | 40 | | { |
| 0 | 41 | | if (options.label == dropDown.options[currentIndex].text) |
| 0 | 42 | | SetParameterValue(options.value); |
| | 43 | | } |
| 0 | 44 | | } |
| | 45 | | } |