82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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,
|
|
Cookware,
|
|
Special
|
|
}
|
|
|
|
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 List<GameObject> _content = new();
|
|
|
|
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;
|
|
SetActiveContents(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;
|
|
private void SetActiveContents(bool isActive)
|
|
{
|
|
foreach (var content in _content)
|
|
{
|
|
content.SetActive(isActive);
|
|
}
|
|
}
|
|
public void OnInteract()
|
|
{
|
|
_onSelected?.Invoke(TabType);
|
|
}
|
|
}
|
|
} |