using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; namespace KairoEngine.UI { [CreateAssetMenu(fileName = "Ui Library", menuName = "KairoEngine/UiSystemLibrary"), HideMonoScript] public class UiSystemLibrary : ScriptableObject { public List elements = new List(); public void Load(Transform parent) { for (int i = 0; i < elements.Count; i++) InstantiateElement(parent, i); } private void InstantiateElement(Transform parent, int index) { if(elements[index] == null) { Debug.LogError("Error loading UI Library item, missing prefab."); return; } var obj = GameObject.Instantiate(elements[index].uiPrefab, parent); obj.name = (elements[index].uiPrefab.name).Replace("Prefab", ""); IUiSystemElement el = obj.GetComponent(); if(el == null) el = obj.GetComponentInChildren(); if(el != null) { if(elements[index].visibleOnStart) UiManager.ShowElement(el); else UiManager.HideElement(el); } else { if(elements[index].visibleOnStart) obj.SetActive(true); else obj.SetActive(false); } } } [System.Serializable] public class UiSystemLibraryItem { [HorizontalGroup("line", 0.015f), HideLabel] public bool visibleOnStart = false; [HorizontalGroup("line", 0.985f), HideLabel] public GameObject uiPrefab; } }