using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using KairoEngine.UI; using KairoEngine.UI.InteractionHandler; using KairoEngine.GameTools.InteractionTools; using Sirenix.OdinInspector; using KairoEngine.Core; using UniRx; namespace KairoEngine.GameTools.UI { public class ToolbarUi : MonoBehaviour, IClickHandler { public InteractionToolsManager interactionToolsManager; public MenuUI menuUi; private List selectButtons = new List(); private int toolIndex; void Start() { CreateMenu(); toolIndex = interactionToolsManager.currentTools; } void Update() { if(interactionToolsManager.currentTools != toolIndex) { toolIndex = interactionToolsManager.currentTools; for (int i = 0; i < interactionToolsManager.tools.Count; i++) { //if(selectButtons[i] == null) selectButtons[i] = menuUi.buttons[i].button.gameObject.GetComponent(); if(toolIndex == i && selectButtons[i] != null) selectButtons[i].Select(); else if(selectButtons[i] != null) selectButtons[i].Deselect(); } } } public void OnClick(string title) { for (int i = 0; i < interactionToolsManager.tools.Count; i++) { if(interactionToolsManager.tools[i].name == title) { if(selectButtons[i] != null) selectButtons[i].Select(); interactionToolsManager.ChangeTool(i); } else selectButtons[i].Deselect(); } } [Button("Create")] public void CreateMenu() { if(interactionToolsManager == null) return; menuUi.DestroyMenu(); selectButtons.Clear(); List menuData = new List(); for (int i = 0; i < interactionToolsManager.tools.Count; i++) { MenuButtomData data = new MenuButtomData(); data.title = interactionToolsManager.tools[i].gameObject.name; data.showTooltip = false; data.subMenuParent = true; data.action = interactionToolsManager.tools[i].gameObject.name; data.graphic = interactionToolsManager.tools[i].GetComponent().GetIcon(); menuData.Add(data); } menuUi.buttons = menuData; menuUi.CreateMenu(); Timer.ExecuteRealTime(100, () => { for (int i = 0; i < interactionToolsManager.tools.Count; i++) { selectButtons.Add(menuUi.buttons[i].button.gameObject.GetComponent()); } selectButtons[interactionToolsManager.currentTools].Select(); }); } } }