using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Core.ConfigOptions; using Sirenix.OdinInspector; namespace KairoEngine.UI.ConfigOptions { [HideMonoScript] public class ConfigOptionsUI : MonoBehaviour { [LabelText("Config Options")] public List list = new List(); public GameObject sliderPrefab; public GameObject checkboxPrefab; public GameObject dropdownPrefab; public Transform container; private List configOptionsGameObjects; private void Awake() { if(sliderPrefab == null) Debug.LogError("sliderPrefab is missing in ConfigOptionsUi.", this.gameObject); if(checkboxPrefab == null) Debug.LogError("checkboxPrefab is missing in ConfigOptionsUi.", this.gameObject); if(dropdownPrefab == null) Debug.LogError("dropdownPrefab is missing in ConfigOptionsUi.", this.gameObject); if(container == null) Debug.LogError("container is missing in ConfigOptionsUi.", this.gameObject); } private void Start() { Timer.Execute(2000f, () => { GenerateConfigMenu(); }); } public void GenerateConfigMenu() { if(configOptionsGameObjects != null) { for (int i = 0; i < configOptionsGameObjects.Count; i++) { Destroy(configOptionsGameObjects[i]); } } configOptionsGameObjects = new List(); for (int i = 0; i < list.Count; i++) { GameObject obj = null; switch(list[i].uiElementType) { case ConfigOptionUIType.Slider: obj = Instantiate(sliderPrefab, container); obj.GetComponent().Setup(list[i]); break; case ConfigOptionUIType.Checkbox: obj = Instantiate(checkboxPrefab, container); obj.GetComponent().Setup(list[i]); break; case ConfigOptionUIType.Dropdown: obj = Instantiate(dropdownPrefab, container); obj.GetComponent().Setup(list[i]); break; default: break; } if(obj != null) configOptionsGameObjects.Add(obj); } } } }