ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/TabButtonUi.cs

55 lines
1.4 KiB
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace DDD
{
public enum RestaurantManagementSectionType
{
None = 0,
Menu,
Cookware,
Worker
}
public enum InventoryCategoryType
{
None = 0,
Food,
Drink,
Ingredient
}
public class TabButtonUi<T> : MonoBehaviour, ITabSelectable<T>, IInteractableUi where T : Enum
{
[field: SerializeField] public T TabType { get; private set; }
[SerializeField] private Button _button;
[SerializeField] private TextMeshProUGUI _label;
[SerializeField] private GameObject _content;
private Action<T> _onSelected;
public void Initialize(Action<T> onSelected)
{
_onSelected = onSelected;
_button.onClick.AddListener(() => _onSelected?.Invoke(TabType));
}
public void SetSelected(bool isSelected)
{
if (_content)
{
_content.SetActive(isSelected);
}
_button.interactable = !isSelected;
}
public bool ButtonIsInteractable => _button != null && _button.interactable;
public GameObject ButtonGameObject => _button?.gameObject;
public void OnInteract()
{
_onSelected?.Invoke(TabType);
}
}
}