61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using BlueWater.Items;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class ItemSlotUi : MonoBehaviour
|
|
{
|
|
[field: SerializeField]
|
|
public ItemSlot ItemSlot { get; private set; }
|
|
|
|
[SerializeField, Required]
|
|
private Toggle _itemSelectToggle;
|
|
|
|
[SerializeField, Required]
|
|
private Image _image;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _nameText;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _weightText;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _countText;
|
|
|
|
public bool ToggleIsOn => _itemSelectToggle.isOn;
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
_itemSelectToggle = transform.Find("ItemSelectToggle").GetComponent<Toggle>();
|
|
_image = transform.Find("Image").GetComponent<Image>();
|
|
_nameText = transform.Find("NameText").GetComponent<TMP_Text>();
|
|
_weightText = transform.Find("WeightText").GetComponent<TMP_Text>();
|
|
_countText = transform.Find("CountText").GetComponent<TMP_Text>();
|
|
}
|
|
|
|
public void InitializeData(ItemSlot itemSlot)
|
|
{
|
|
ItemSlot = itemSlot;
|
|
|
|
UpdateData(itemSlot);
|
|
}
|
|
|
|
public void UpdateData(ItemSlot itemSlot)
|
|
{
|
|
var item = ItemManager.Instance.ItemDictionary[itemSlot.Idx];
|
|
_image.sprite = item.Sprite;
|
|
_nameText.text = item.Name;
|
|
_weightText.text = item.Weight * ItemSlot.Count + "kg";
|
|
_countText.text = "x" + ItemSlot.Count;
|
|
}
|
|
|
|
public void ToggleOn() => _itemSelectToggle.isOn = true;
|
|
public void ToggleOff() => _itemSelectToggle.isOn = false;
|
|
public void ClickToggle() => _itemSelectToggle.isOn = !_itemSelectToggle.isOn;
|
|
}
|
|
} |