123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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<SelectedButton> selectButtons = new List<SelectedButton>();
- 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<SelectedButton>();
- 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<MenuButtomData> menuData = new List<MenuButtomData>();
- 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<IInteractionTool>().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<SelectedButton>());
- }
- selectButtons[interactionToolsManager.currentTools].Select();
- });
-
- }
-
- }
- }
|