UiSystemLibrary.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. namespace KairoEngine.UI
  6. {
  7. [CreateAssetMenu(fileName = "Ui Library", menuName = "KairoEngine/UiSystemLibrary"), HideMonoScript]
  8. public class UiSystemLibrary : ScriptableObject
  9. {
  10. public List<UiSystemLibraryItem> elements = new List<UiSystemLibraryItem>();
  11. public void Load(Transform parent)
  12. {
  13. for (int i = 0; i < elements.Count; i++) InstantiateElement(parent, i);
  14. }
  15. private void InstantiateElement(Transform parent, int index)
  16. {
  17. if(elements[index] == null)
  18. {
  19. Debug.LogError("Error loading UI Library item, missing prefab.");
  20. return;
  21. }
  22. var obj = GameObject.Instantiate(elements[index].uiPrefab, parent);
  23. obj.name = (elements[index].uiPrefab.name).Replace("Prefab", "");
  24. }
  25. }
  26. [System.Serializable]
  27. public class UiSystemLibraryItem
  28. {
  29. [HorizontalGroup("line", 0.015f), HideLabel] public bool visibleOnStart = false;
  30. [HorizontalGroup("line", 0.985f), HideLabel] public GameObject uiPrefab;
  31. }
  32. }