ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/TabUi/TabButtonUi.cs
2025-08-04 08:09:01 +09:00

95 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
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();
[SerializeField] private bool _isEnabled = true;
private Action<T> _onSelected;
private bool _isSelected;
private readonly int _canDisabled = Animator.StringToHash("CanDisabled");
private void OnEnable()
{
if (_isEnabled == false)
{
_animator.SetBool(_canDisabled, true);
return;
}
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 Task OnInteract()
{
_onSelected?.Invoke(TabType);
return Task.CompletedTask;
}
}
}