56 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIBattleItem : MonoBehaviour
{
[SerializeField] private Image _image;
[SerializeField] private Button _button;
[SerializeField] private Text num;
private int itemID = 0;
private void Awake()
{
_button = GetComponent<Button>();
}
private void OnEnable()
{
_button.onClick.AddListener(OnButtonEvent);
}
private void OnDisable()
{
_button.onClick.RemoveListener(OnButtonEvent);
}
public void ResetData(int id)
{
itemID = id;
var data = JsonTab.Instance.tables.Item.Get(id);
_image.sprite = AssetBundleManager.ins.Sprite(data.Icon, AtlasType.ItemIcon);
ResetText();
}
public void ResetText()
{
BattleManager.ins.GetItemNum(itemID,out var itemNum);
num.text = (DataManager.GetItem(itemID) - itemNum).ToString();
}
private void OnButtonEvent()
{
BattleManager.ins.GetItemNum(itemID,out var itemNum);
if (DataManager.GetItem(itemID) - itemNum-1>=0)
{
BattleManager.ins.AddItem(itemID,out bool bo);
if (bo)
{
UIMgr.ins.ResetBattleReadyPanel();
}
}
}
}