ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/TabUi/TabButtonUi.cs

76 lines
1.9 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, IInteractableUi where T : Enum
{
[field: SerializeField] public T TabType { get; private set; }
[SerializeField] private Button _button;
[SerializeField] private Animator _animator;
[SerializeField] private TextMeshProUGUI _label;
[SerializeField] private GameObject _content;
private Action<T> _onSelected;
private bool _isSelected;
private void OnEnable()
{
if (_isSelected)
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Selected));
}
}
public void Initialize(Action<T> onSelected)
{
gameObject.SetActive(true);
_onSelected = onSelected;
_button.onClick.AddListener(() => _onSelected?.Invoke(TabType));
}
public void SetSelected(bool isSelected)
{
_isSelected = isSelected;
if (_content)
{
_content.SetActive(isSelected);
}
_button.interactable = !_isSelected;
if (_isSelected)
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Selected));
}
else
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Normal));
}
}
public bool ButtonIsInteractable => _button != null && _button.interactable;
public GameObject ButtonGameObject => _button?.gameObject;
public void OnInteract()
{
_onSelected?.Invoke(TabType);
}
}
}