77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Panel_TopRightToolBar : MonoBehaviour
|
|
{
|
|
private Dictionary<Button, ToolPopupBase> tabMenus = new();
|
|
public Button currentTabButton;
|
|
|
|
public void Awake()
|
|
{
|
|
var buttonDictionary = transform.FindComponentDictionary<Button>();
|
|
|
|
var toolPopups = FindObjectsByType<ToolPopupBase>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
|
|
|
foreach (var tabButton in buttonDictionary.Values)
|
|
{
|
|
SettingTabMenu(tabButton, toolPopups);
|
|
tabButton.onClick.AddListener(() => SetTabMenu(tabButton));
|
|
}
|
|
}
|
|
private void SettingTabMenu(Button tabButton, ToolPopupBase[] dataContents)
|
|
{
|
|
foreach (var dataContent in dataContents)
|
|
{
|
|
var tabMenuName = tabButton.name.Replace("Button_", "");
|
|
|
|
if (dataContent.name.Contains(tabMenuName))
|
|
{
|
|
dataContent.onClose += ResetTab;
|
|
tabMenus.Add(tabButton, dataContent);
|
|
}
|
|
}
|
|
}
|
|
public void SetTabMenu(Button tabButton)
|
|
{
|
|
ChangedTab(tabButton);
|
|
}
|
|
private void ChangedTab(Button tabButton)
|
|
{
|
|
if (currentTabButton != null && currentTabButton != tabButton)
|
|
{
|
|
currentTabButton.image.color = Color.white;
|
|
|
|
var preSelected = currentTabButton.transform.GetChild(0);
|
|
preSelected.gameObject.SetActive(false);
|
|
IsSetMenu(currentTabButton, false);
|
|
}
|
|
currentTabButton = tabButton;
|
|
currentTabButton.image.color = Color.black;
|
|
|
|
var selected = currentTabButton.transform.GetChild(0);
|
|
selected.gameObject.SetActive(true);
|
|
IsSetMenu(tabButton, true);
|
|
}
|
|
private void ResetTab()
|
|
{
|
|
currentTabButton.image.color = Color.white;
|
|
|
|
var preSelected = currentTabButton.transform.GetChild(0);
|
|
preSelected.gameObject.SetActive(false);
|
|
IsSetMenu(currentTabButton, false);
|
|
}
|
|
private void IsSetMenu(Button tabButton, bool isActive)
|
|
{
|
|
if (tabMenus.ContainsKey(tabButton))
|
|
{
|
|
tabMenus[currentTabButton].SetActive(isActive);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("아직 할당 되지 않은 기능입니다.");
|
|
}
|
|
}
|
|
}
|