110 lines
3.4 KiB
C#
Raw Normal View History

2024-12-16 17:25:10 +08:00
using System;
2024-12-04 17:26:27 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-12-16 17:25:10 +08:00
using UnityEngine.UI;
2024-12-04 17:26:27 +08:00
public class StoreItem : MonoBehaviour
{
2024-12-16 17:25:10 +08:00
[SerializeField] private int id;
[SerializeField] private Image icon;
2024-12-22 20:35:00 +08:00
[SerializeField] private Sprite storeIcon;
2024-12-16 17:25:10 +08:00
[SerializeField] private Text name;
[SerializeField] private Text num;
[SerializeField] private Text getNum;
[SerializeField] private Button _button;
private void OnEnable()
{
_button.onClick.AddListener(BuyEvent);
}
private void OnDisable()
{
_button.onClick.RemoveListener(BuyEvent);
}
public void ResetItem()
2024-12-04 17:26:27 +08:00
{
2024-12-16 17:25:10 +08:00
var rID=DataManager.GetDStore(id);
var data = JsonTab.Instance.tables.StoreRandom.Get(rID);
var itemData = JsonTab.Instance.tables.Item.Get(data.GiftID);
2024-12-22 20:35:00 +08:00
if (storeIcon!=null)
{
icon.sprite = storeIcon;
}
else
{
icon.sprite = AssetBundleManager.ins.Sprite(itemData.Icon, AtlasType.ItemIcon);
}
2024-12-16 17:25:10 +08:00
name.text = itemData.Propname;
getNum.text = "X"+data.Quantity.ToString();
var glodW = (float)DataManager.GetDDiscount(id)/10*data.GiftDiamond;
int g = (int)glodW;
2024-12-22 20:35:00 +08:00
if (id == 101 || id == 103)
{
if (DataManager.NextDay("storeDay"+id))
{
num.text = "免费获得";
}
else
{
num.text = "已售罄";
}
}
else if (id == 102 || id == 104)
{
num.text = "观看视频获得";
}
else
{
num.text = g.ToString();
}
2024-12-04 17:26:27 +08:00
}
2024-12-16 17:25:10 +08:00
private void BuyEvent()
2024-12-04 17:26:27 +08:00
{
2024-12-16 17:25:10 +08:00
var rID=DataManager.GetDStore(id);
var data = JsonTab.Instance.tables.StoreRandom.Get(rID);
var glodW = (float)DataManager.GetDDiscount(id)/10*data.GiftDiamond;
int g = (int)glodW;
2024-12-22 20:35:00 +08:00
if (id==101||id==103)
{
if (DataManager.NextDay("storeDay"+id))
{
DataManager.SetTime("storeDay"+id);
DataManager.RemoveItem(2,data.GiftDiamond);
DataManager.AddItem(data.GiftID,data.Quantity);
List<ItemDataNum> itemList = new List<ItemDataNum>();
var itemNum = new ItemDataNum(data.GiftID, data.Quantity);
itemList.Add(itemNum);
StorePanel.ins.OpenRewardPanel(itemList);
}
}
else if (id==102||id==104)
{
ADSystem.getInstance().PlayAd(() =>
{
DataManager.RemoveItem(2,data.GiftDiamond);
DataManager.AddItem(data.GiftID,data.Quantity);
List<ItemDataNum> itemList = new List<ItemDataNum>();
var itemNum = new ItemDataNum(data.GiftID, data.Quantity);
itemList.Add(itemNum);
StorePanel.ins.OpenRewardPanel(itemList);
});
}
else
{
if (DataManager.GetItem(2)>=g)
{
DataManager.RemoveItem(2,data.GiftDiamond);
DataManager.AddItem(data.GiftID,data.Quantity);
List<ItemDataNum> itemList = new List<ItemDataNum>();
var itemNum = new ItemDataNum(data.GiftID, data.Quantity);
itemList.Add(itemNum);
StorePanel.ins.OpenRewardPanel(itemList);
}
2024-12-16 17:25:10 +08:00
}
2024-12-04 17:26:27 +08:00
}
}