ProjectDDD/Assets/_DDD/_Scripts/GameUi/RestaurantManagementUi/ItemUi/ItemSlotUi.cs

57 lines
2.1 KiB
C#
Raw Normal View History

2025-07-29 15:56:47 +00:00
using System;
2025-07-29 18:18:16 +00:00
using System.Threading.Tasks;
2025-07-25 07:58:53 +00:00
using TMPro;
using UnityEngine;
2025-07-29 18:18:16 +00:00
using UnityEngine.AddressableAssets;
2025-07-29 15:56:47 +00:00
using UnityEngine.EventSystems;
2025-07-25 07:58:53 +00:00
using UnityEngine.UI;
namespace DDD
{
2025-07-29 15:56:47 +00:00
public class ItemSlotUi : MonoBehaviour, ISelectHandler
2025-07-25 07:58:53 +00:00
{
[SerializeField] private Button _button;
2025-07-29 18:18:16 +00:00
[SerializeField] private Image _backgroundImage;
2025-07-25 07:58:53 +00:00
[SerializeField] private Image _icon;
[SerializeField] private TextMeshProUGUI _countText;
[SerializeField] private Image _markImage;
2025-07-29 18:18:16 +00:00
[SerializeField] private Animator _animator;
2025-07-25 07:58:53 +00:00
public ItemViewModel Model { get; private set; }
2025-07-29 15:56:47 +00:00
public IItemSlotUiStrategy Strategy { get; private set; }
2025-07-25 07:58:53 +00:00
2025-07-29 18:18:16 +00:00
public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
2025-07-25 07:58:53 +00:00
{
Model = model;
2025-07-29 15:56:47 +00:00
Strategy = strategy;
2025-07-29 18:18:16 +00:00
await Strategy.Setup(this, model);
var controller = await strategy.GetAnimatorController();
_animator.runtimeAnimatorController = controller;
2025-07-25 07:58:53 +00:00
}
2025-07-29 15:56:47 +00:00
2025-07-29 18:18:16 +00:00
public void SetBackgroundColor(Color color) => _backgroundImage.color = color;
2025-07-29 15:56:47 +00:00
public void SetIcon(Sprite sprite) => _icon.sprite = sprite;
public void SetCount(int count)
2025-07-27 19:32:41 +00:00
{
2025-07-29 15:56:47 +00:00
_countText.text = count.ToString();
_countText.color = count > 0 ? Color.white : Color.red;
2025-07-25 07:58:53 +00:00
}
2025-07-29 15:56:47 +00:00
public void ShowCount() => _countText.gameObject.SetActive(true);
public void HideCount() => _countText.gameObject.SetActive(false);
public void ShowMark(Sprite sprite)
2025-07-25 07:58:53 +00:00
{
2025-07-29 15:56:47 +00:00
_markImage.sprite = sprite;
2025-07-25 07:58:53 +00:00
_markImage.gameObject.SetActive(true);
}
2025-07-29 15:56:47 +00:00
public void HideMark() => _markImage.gameObject.SetActive(false);
public void SetButtonInteractable(bool interactable) => _button.interactable = interactable;
2025-07-25 07:58:53 +00:00
2025-07-29 15:56:47 +00:00
public void SetActive(bool value) => gameObject.SetActive(value);
public void OnSelect(BaseEventData eventData)
2025-07-25 07:58:53 +00:00
{
2025-07-29 15:56:47 +00:00
RestaurantEvents.ItemSlotSelectedEvent.Model = Model;
EventBus.Broadcast(RestaurantEvents.ItemSlotSelectedEvent);
2025-07-25 07:58:53 +00:00
}
}
}