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

123 lines
3.2 KiB
C#
Raw Normal View History

2025-07-25 07:58:53 +00:00
using System;
using System.Collections.Generic;
2025-08-03 23:09:01 +00:00
using System.Threading.Tasks;
2025-07-25 07:58:53 +00:00
using UnityEngine;
using UnityEngine.UI;
namespace DDD
{
2025-08-16 23:57:23 +00:00
public enum SectionButtonType
2025-07-25 07:58:53 +00:00
{
None = 0,
Menu,
Cookware,
Worker
}
2025-08-16 23:57:23 +00:00
2025-07-25 07:58:53 +00:00
public enum InventoryCategoryType
{
None = 0,
2025-08-16 23:57:23 +00:00
Food, // 음식
Drink, // 음료
Ingredient, // 재료
Cookware, // 조리도구
Special // 특수 아이템
2025-07-25 07:58:53 +00:00
}
2025-08-16 23:57:23 +00:00
/// <summary>
/// 공통 탭 버튼 UI 클래스
/// 제네릭 없이 탭을 관리합니다.
/// </summary>
public class CommonTabButtonUi : MonoBehaviour, IInteractableUi, ITabButton
2025-07-25 07:58:53 +00:00
{
[SerializeField] private Button _button;
2025-07-29 20:57:19 +00:00
[SerializeField] private Animator _animator;
[SerializeField] private List<GameObject> _content = new();
2025-08-16 23:57:23 +00:00
2025-07-30 10:38:12 +00:00
[SerializeField] private bool _isEnabled = true;
2025-07-25 07:58:53 +00:00
2025-08-16 23:57:23 +00:00
private Action<int> _onSelected;
2025-07-29 20:57:19 +00:00
private bool _isSelected;
2025-08-16 23:57:23 +00:00
// ITabButton 인터페이스 구현을 위한 필드
private int _tabButtonValue;
public event Action<int> OnTabClicked;
2025-07-30 10:38:12 +00:00
private readonly int _canDisabled = Animator.StringToHash("CanDisabled");
2025-07-29 20:57:19 +00:00
2025-08-16 23:57:23 +00:00
// ITabButton 인터페이스 구현
public int TabValue => _tabButtonValue;
public bool IsInteractable => _button != null && _button.interactable;
2025-07-29 20:57:19 +00:00
private void OnEnable()
{
2025-07-30 10:38:12 +00:00
if (_isEnabled == false)
{
_animator.SetBool(_canDisabled, true);
return;
}
2025-08-16 23:57:23 +00:00
if (_isSelected == true)
2025-07-29 20:57:19 +00:00
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Selected));
}
}
2025-07-25 07:58:53 +00:00
2025-08-16 23:57:23 +00:00
public void Initialize(Action<int> onSelected)
2025-07-25 07:58:53 +00:00
{
2025-07-29 20:57:19 +00:00
gameObject.SetActive(true);
2025-07-25 07:58:53 +00:00
_onSelected = onSelected;
2025-08-16 23:57:23 +00:00
_button.onClick.AddListener(() => _onSelected?.Invoke(_tabButtonValue));
2025-07-25 07:58:53 +00:00
}
public void SetSelected(bool isSelected)
{
2025-08-16 23:57:23 +00:00
if (_isEnabled == false) return;
2025-07-29 20:57:19 +00:00
_isSelected = isSelected;
SetActiveContents(isSelected);
2025-08-16 23:57:23 +00:00
if (_isSelected == true)
2025-07-29 20:57:19 +00:00
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Selected));
}
else
{
_animator.SetTrigger(nameof(DefaultAnimatorParams.Normal));
}
2025-07-25 07:58:53 +00:00
}
2025-08-16 23:57:23 +00:00
public void SetTabData(int tabValue)
{
if (_isEnabled == false) return;
_tabButtonValue = tabValue;
// 버튼 클릭 이벤트 설정
if (_button != null)
{
_button.onClick.RemoveAllListeners();
_button.onClick.AddListener(() =>
{
_onSelected?.Invoke(tabValue);
OnTabClicked?.Invoke(tabValue);
});
}
}
private void SetActiveContents(bool isActive)
{
foreach (var content in _content)
{
content.SetActive(isActive);
}
}
2025-08-16 23:57:23 +00:00
public void OnInteract()
2025-07-29 15:56:47 +00:00
{
2025-08-16 23:57:23 +00:00
_onSelected?.Invoke(_tabButtonValue);
OnTabClicked?.Invoke(_tabButtonValue);
2025-07-29 15:56:47 +00:00
}
2025-07-25 07:58:53 +00:00
}
2025-08-16 23:57:23 +00:00
}