using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using Sirenix.OdinInspector; using KairoEngine.UI.Tooltips; using KairoEngine.UI.InteractionHandler; namespace KairoEngine.UI { [HideMonoScript] public class ColumnMenuUI : MenuUI { [BoxGroup("Settings"), OnInspectorInit("EditorSetup")] public GameObject subMenuPrefab; [BoxGroup("Settings")] public RectTransform subMenusParent; private GameObject mainMenu; private List subMenus = new List(); public override void Start() { useSubMenus = true; if(handler == null) handler = gameObject.GetComponent(); if(createMenuOnStart) { DestroyMenu(); CreateMenu(); } } public override void OnClick(string title) { for (int i = 0; i < buttons.Count; i++) { if(buttons[i].title == title) { if(buttons[i].subMenuParent) OpenSubMenu(title); if(buttons[i].action != "" && handler != null) { handler.OnClick(buttons[i].action); } } } } public override void CreateMenu() => CreateMenus(); public void CreateMenus() { mainMenu = Instantiate(subMenuPrefab, menuParent); for (int i = 0; i < buttons.Count; i++) { if(string.IsNullOrEmpty(buttons[i].parent)) { var btn = CreateButton(buttons[i], mainMenu.transform); buttons[i].button = btn; var subMenu = Instantiate(subMenuPrefab, subMenusParent); subMenu.name = $"SubMenu {buttons[i].title}"; for (int a = 0; a < buttons.Count; a++) { if(buttons[a].parent == buttons[i].title) { var subBtn = CreateButton(buttons[a], subMenu.transform); buttons[a].button = subBtn; } } subMenu.SetActive(false); subMenus.Add(subMenu); } } } public override void DestroyMenu() => DestroyMenus(); public void DestroyMenus() { for (int i = 0; i < subMenus.Count; i++) { Destroy(subMenus[i]); } subMenus = new List(); #if UNITY_EDITOR DestroyImmediate(mainMenu); #else Destroy(mainMenu); #endif buttons = new List(); } public void OpenSubMenu(string title) { for (int i = 0; i < subMenus.Count; i++) { if($"SubMenu {title}" == subMenus[i].name) subMenus[i].SetActive(true); else subMenus[i].SetActive(false); } } public void EditorSetup() { useSubMenus = true; } } }