40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
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;
|
|
|
|
public void InitData(ItemSlot itemSlot)
|
|
{
|
|
ItemSlot = itemSlot;
|
|
|
|
UpdateData(itemSlot);
|
|
}
|
|
|
|
public void UpdateData(ItemSlot itemSlot)
|
|
{
|
|
var item = ItemManager.Inst.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;
|
|
}
|
|
} |