|
@@ -14,14 +14,19 @@ namespace KairoEngine.UI
|
|
{
|
|
{
|
|
|
|
|
|
[BoxGroup("Settings"), OnInspectorInit("EditorSetup")] public GameObject subMenuPrefab;
|
|
[BoxGroup("Settings"), OnInspectorInit("EditorSetup")] public GameObject subMenuPrefab;
|
|
|
|
+ [BoxGroup("Settings")] public GameObject subMenuButtonPrefab;
|
|
[BoxGroup("Settings")] public RectTransform subMenusParent;
|
|
[BoxGroup("Settings")] public RectTransform subMenusParent;
|
|
|
|
+ [BoxGroup("Settings")] public bool instantiateMainMenuGroup = true;
|
|
|
|
+ [BoxGroup("Settings")] public bool keepMenuButtonsSelected = false;
|
|
|
|
+ [BoxGroup("Settings")] public bool keepSubMenuButtonsSelected = false;
|
|
private GameObject mainMenu;
|
|
private GameObject mainMenu;
|
|
private List<GameObject> subMenus = new List<GameObject>();
|
|
private List<GameObject> subMenus = new List<GameObject>();
|
|
|
|
+ private List<SelectedButton> selectButtons = new List<SelectedButton>();
|
|
|
|
|
|
public override void Start()
|
|
public override void Start()
|
|
{
|
|
{
|
|
useSubMenus = true;
|
|
useSubMenus = true;
|
|
- if(handler == null) handler = gameObject.GetComponent<IClickHandler>();
|
|
|
|
|
|
+ if(handler == null) handler = gameObject.GetComponents<IClickHandler>()[1];
|
|
if(createMenuOnStart)
|
|
if(createMenuOnStart)
|
|
{
|
|
{
|
|
DestroyMenu();
|
|
DestroyMenu();
|
|
@@ -35,11 +40,17 @@ namespace KairoEngine.UI
|
|
{
|
|
{
|
|
if(buttons[i].title == title)
|
|
if(buttons[i].title == title)
|
|
{
|
|
{
|
|
- if(buttons[i].subMenuParent) OpenSubMenu(title);
|
|
|
|
|
|
+ if(buttons[i].subMenuParent)
|
|
|
|
+ {
|
|
|
|
+ OpenSubMenu(title);
|
|
|
|
+ SelectParentButton(i);
|
|
|
|
+ }
|
|
if(buttons[i].action != "" && handler != null)
|
|
if(buttons[i].action != "" && handler != null)
|
|
{
|
|
{
|
|
|
|
+ SelectChildButton(i);
|
|
handler.OnClick(buttons[i].action);
|
|
handler.OnClick(buttons[i].action);
|
|
}
|
|
}
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -48,12 +59,14 @@ namespace KairoEngine.UI
|
|
|
|
|
|
public void CreateMenus()
|
|
public void CreateMenus()
|
|
{
|
|
{
|
|
- mainMenu = Instantiate(subMenuPrefab, menuParent);
|
|
|
|
|
|
+ if(instantiateMainMenuGroup) mainMenu = Instantiate(subMenuPrefab, menuParent);
|
|
|
|
+ else mainMenu = menuParent.gameObject;
|
|
for (int i = 0; i < buttons.Count; i++)
|
|
for (int i = 0; i < buttons.Count; i++)
|
|
{
|
|
{
|
|
if(string.IsNullOrEmpty(buttons[i].parent))
|
|
if(string.IsNullOrEmpty(buttons[i].parent))
|
|
{
|
|
{
|
|
- var btn = CreateButton(buttons[i], mainMenu.transform);
|
|
|
|
|
|
+ var btn = CreateButton(buttons[i], mainMenu.transform, buttonPrefab);
|
|
|
|
+ selectButtons.Add(btn.GetComponent<SelectedButton>());
|
|
buttons[i].button = btn;
|
|
buttons[i].button = btn;
|
|
var subMenu = Instantiate(subMenuPrefab, subMenusParent);
|
|
var subMenu = Instantiate(subMenuPrefab, subMenusParent);
|
|
subMenu.name = $"SubMenu {buttons[i].title}";
|
|
subMenu.name = $"SubMenu {buttons[i].title}";
|
|
@@ -61,7 +74,8 @@ namespace KairoEngine.UI
|
|
{
|
|
{
|
|
if(buttons[a].parent == buttons[i].title)
|
|
if(buttons[a].parent == buttons[i].title)
|
|
{
|
|
{
|
|
- var subBtn = CreateButton(buttons[a], subMenu.transform);
|
|
|
|
|
|
+ var subBtn = CreateButton(buttons[a], subMenu.transform, subMenuButtonPrefab ?? buttonPrefab);
|
|
|
|
+ selectButtons.Add(subBtn.GetComponent<SelectedButton>());
|
|
buttons[a].button = subBtn;
|
|
buttons[a].button = subBtn;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -77,13 +91,19 @@ namespace KairoEngine.UI
|
|
{
|
|
{
|
|
for (int i = 0; i < subMenus.Count; i++)
|
|
for (int i = 0; i < subMenus.Count; i++)
|
|
{
|
|
{
|
|
|
|
+ #if UNITY_EDITOR
|
|
|
|
+ DestroyImmediate(subMenus[i]);
|
|
|
|
+ #else
|
|
Destroy(subMenus[i]);
|
|
Destroy(subMenus[i]);
|
|
|
|
+ #endif
|
|
}
|
|
}
|
|
subMenus = new List<GameObject>();
|
|
subMenus = new List<GameObject>();
|
|
#if UNITY_EDITOR
|
|
#if UNITY_EDITOR
|
|
- DestroyImmediate(mainMenu);
|
|
|
|
|
|
+ if(instantiateMainMenuGroup) DestroyImmediate(mainMenu);
|
|
|
|
+ else foreach (var btn in buttons) DestroyImmediate(btn.button.gameObject);
|
|
#else
|
|
#else
|
|
- Destroy(mainMenu);
|
|
|
|
|
|
+ if(instantiateMainMenuGroup) Destroy(mainMenu);
|
|
|
|
+ else foreach (var btn in buttons) Destroy(btn.button.gameObject);
|
|
#endif
|
|
#endif
|
|
buttons = new List<MenuButtomData>();
|
|
buttons = new List<MenuButtomData>();
|
|
}
|
|
}
|
|
@@ -92,14 +112,54 @@ namespace KairoEngine.UI
|
|
{
|
|
{
|
|
for (int i = 0; i < subMenus.Count; i++)
|
|
for (int i = 0; i < subMenus.Count; i++)
|
|
{
|
|
{
|
|
|
|
+ if(subMenus[i] == null) continue;
|
|
if($"SubMenu {title}" == subMenus[i].name) subMenus[i].SetActive(true);
|
|
if($"SubMenu {title}" == subMenus[i].name) subMenus[i].SetActive(true);
|
|
else subMenus[i].SetActive(false);
|
|
else subMenus[i].SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void CloseSubMenus()
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < subMenus.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if(subMenus[i] != null) subMenus[i].SetActive(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void EditorSetup()
|
|
public void EditorSetup()
|
|
{
|
|
{
|
|
useSubMenus = true;
|
|
useSubMenus = true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void SelectParentButton(int index)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < buttons.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if(i != index && buttons[i].subMenuParent) selectButtons[i].Deselect();
|
|
|
|
+ else if(i == index) selectButtons[i].Select();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void SelectChildButton(int index)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < buttons.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if(i != index && !buttons[i].subMenuParent) selectButtons[i].Deselect();
|
|
|
|
+ else if(i == index) selectButtons[i].Select();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void DeselectChildButtons()
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < buttons.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ if(!buttons[i].subMenuParent) selectButtons[i].Deselect();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void DeselectAllButtons()
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < buttons.Count; i++) selectButtons[i].Deselect();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|