58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace DDD
|
|
{
|
|
public class ItemSlotUi : MonoBehaviour, ISelectHandler
|
|
{
|
|
[SerializeField] private Button _button;
|
|
[SerializeField] private Image _backgroundImage;
|
|
[SerializeField] private Image _icon;
|
|
[SerializeField] private TextMeshProUGUI _countText;
|
|
[SerializeField] private Image _markImage;
|
|
[SerializeField] private Animator _animator;
|
|
|
|
public ItemViewModel Model { get; private set; }
|
|
public IItemSlotUiStrategy Strategy { get; private set; }
|
|
|
|
public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
|
|
{
|
|
Model = model;
|
|
Strategy = strategy;
|
|
|
|
await Strategy.Setup(this, model);
|
|
var controller = await strategy.GetAnimatorController();
|
|
_animator.runtimeAnimatorController = controller;
|
|
//AssetManager.ReleaseCachedByKey(strategy.AnimatorControllerKey);
|
|
}
|
|
|
|
public void SetBackgroundColor(Color color) => _backgroundImage.color = color;
|
|
public void SetIcon(Sprite sprite) => _icon.sprite = sprite;
|
|
public void SetCount(int count)
|
|
{
|
|
_countText.text = count.ToString();
|
|
_countText.color = count > 0 ? Color.white : Color.red;
|
|
}
|
|
public void ShowCount() => _countText.gameObject.SetActive(true);
|
|
public void HideCount() => _countText.gameObject.SetActive(false);
|
|
public void ShowMark(Sprite sprite)
|
|
{
|
|
_markImage.sprite = sprite;
|
|
_markImage.gameObject.SetActive(true);
|
|
}
|
|
public void HideMark() => _markImage.gameObject.SetActive(false);
|
|
public void SetButtonInteractable(bool interactable) => _button.interactable = interactable;
|
|
|
|
public void SetActive(bool value) => gameObject.SetActive(value);
|
|
public void OnSelect(BaseEventData eventData)
|
|
{
|
|
RestaurantEvents.ItemSlotSelectedEvent.Model = Model;
|
|
EventBus.Broadcast(RestaurantEvents.ItemSlotSelectedEvent);
|
|
}
|
|
}
|
|
} |