1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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<ConfigOptionBase> list = new List<ConfigOptionBase>();
- public GameObject sliderPrefab;
- public GameObject checkboxPrefab;
- public GameObject dropdownPrefab;
- public Transform container;
- private List<GameObject> 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<GameObject>();
- for (int i = 0; i < list.Count; i++)
- {
- GameObject obj = null;
- switch(list[i].uiElementType)
- {
- case ConfigOptionUIType.Slider:
- obj = Instantiate(sliderPrefab, container);
- obj.GetComponent<SliderConfigOptionUI>().Setup(list[i]);
- break;
- case ConfigOptionUIType.Checkbox:
- obj = Instantiate(checkboxPrefab, container);
- obj.GetComponent<CheckboxConfigOptionUI>().Setup(list[i]);
- break;
- case ConfigOptionUIType.Dropdown:
- obj = Instantiate(dropdownPrefab, container);
- obj.GetComponent<DropdownConfigOptionUI>().Setup(list[i]);
- break;
- default:
- break;
- }
- if(obj != null) configOptionsGameObjects.Add(obj);
- }
- }
- }
- }
|