2024-12-11 13:58:55 +08:00

103 lines
2.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ItemButton : MonoBehaviour
{
[SerializeField] private int id;
[SerializeField] private Image _image;
[SerializeField] private TextMeshProUGUI numPro;
[SerializeField] private GameObject obj;
[SerializeField] private TextMeshProUGUI buyNum;
private int buy = 0;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
}
private void OnEnable()
{
}
// Update is called once per frame
void Update()
{
}
private void OnDisable()
{
}
public void SendID()
{
if (DataManager.GetItem(id)-GameSystem.ins.drawingManager.slotNum(id)>0)
{
GameSystem.ins.SaveSeledID(id);
}
else
{
if (obj.activeSelf)
{
if (GameSystem.ins.goldCoin>buy)
{
DataManager.AddItem(id,1);
GameSystem.ins.goldCoin -= buy;
GameSystem.ins.ResetItem();
GameSystem.ins.forgePanel.ResetGold();
}
else
{
GameSystem.ins.forgePanel._buyEventButton.gameObject.SetActive(true);
}
}
}
}
public void SetItemData(int dataID)
{
id = dataID;
var data=JsonTab.Instance.tables.Item.Get(id);
_image.sprite = AssetBundleManager.ins.Sprite(data.Icon, AtlasType.ItemIcon);
numPro.text = (DataManager.GetItem(id)-GameSystem.ins.drawingManager.slotNum(id)).ToString();
if (DataManager.GetItem(id)-GameSystem.ins.drawingManager.slotNum(id)==0)
{
var num = GameSystem.ins.DataAsset.ItemValue(dataID);
if (num>0)
{
obj.SetActive(true);
numPro.gameObject.SetActive(false);
buyNum.text = num.ToString();
buy = num;
}
else
{
obj.SetActive(false);
numPro.gameObject.SetActive(true);
}
}
else
{
obj.SetActive(false);
numPro.gameObject.SetActive(true);
}
}
private void OnMouseDown()
{
}
}