using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StoreItem : MonoBehaviour { [SerializeField] private int id; [SerializeField] private Image icon; [SerializeField] private Image buyIcon; [SerializeField] private Sprite storeIcon; [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() { var rID=DataManager.GetDStore(id); var data = JsonTab.Instance.tables.StoreRandom.Get(rID); var itemData = JsonTab.Instance.tables.Item.Get(data.GiftID); if (storeIcon!=null) { icon.sprite = storeIcon; } else { icon.sprite = AssetBundleManager.ins.Sprite(itemData.Icon, AtlasType.ItemIcon); } name.text = itemData.Propname; getNum.text = "X"+data.Quantity.ToString(); var glodW = (float)DataManager.GetDDiscount(id)/10*data.GiftDiamond; int g = (int)glodW; if (id == 101 || id == 103) { if (DataManager.NextDay("storeDay"+id)) { num.text = "免费获得"; _button.interactable = true; } else { num.text = "已售罄"; _button.interactable = false; } } else if (id == 102 || id == 104) { num.text = "观看视频获得"; } else { num.text = g.ToString(); } } private void BuyEvent() { 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; SoundSystem.ins.ButtonEventAudio(); 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 itemList = new List(); 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 itemList = new List(); 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 itemList = new List(); var itemNum = new ItemDataNum(data.GiftID, data.Quantity); itemList.Add(itemNum); StorePanel.ins.OpenRewardPanel(itemList); } } } }