WXGame/Blacksmith/Assets/Script/UI/StorePanel.cs
DESKTOP-DDTRVOR\asus 84cecc83af 备份数据
2024-12-22 20:35:00 +08:00

103 lines
2.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class StorePanel : MonoBehaviour
{
public static StorePanel ins;
[SerializeField] private List<StoreItem> dayStoreItems;
[SerializeField] private List<PrizeDrawItem> _prizeDrawItems;
[SerializeField] private RewardPanel _panel;
[SerializeField] private GameObject storeParent;
[SerializeField] private GameObject lotteryParent;
[SerializeField] private Button stroe;
[SerializeField] private GameObject stroeback;
[SerializeField] private Button lottery;
[SerializeField] private GameObject lotteryback;
private void Awake()
{
ins = this;
}
private void OnEnable()
{
stroe.onClick.AddListener(StartPanel);
lottery.onClick.AddListener(ResetLottery);
}
private void OnDisable()
{
stroe.onClick.RemoveListener(StartPanel);
lottery.onClick.RemoveListener(ResetLottery);
}
public void StartPanel()
{
if (DataManager.NextDay("open"))
{
SetRandomData(1);
SetRandomData(2);
SetRandomData(3);
SetRandomData(4);
SetRandomData(5);
SetRandomData(6);
SetRandomData(101);
SetRandomData(102);
SetRandomData(103);
SetRandomData(104);
DataManager.SetTime("open");
}
foreach (var s in dayStoreItems)
{
s.ResetItem();
}
_panel.gameObject.SetActive(false);
storeParent.SetActive(true);
lotteryParent.SetActive(false);
stroeback.gameObject.SetActive(true);
lotteryback.gameObject.SetActive(false);
}
public void ResetLottery()
{
foreach (var prize in _prizeDrawItems)
{
prize.SetData();
}
_panel.gameObject.SetActive(false);
storeParent.SetActive(false);
lotteryParent.SetActive(true);
stroeback.gameObject.SetActive(false);
lotteryback.gameObject.SetActive(true);
}
public void SetRandomData(int id)
{
var data = JsonTab.Instance.tables.Store.Get(id);
var rID = data.Itemrefresh[Random.Range(0, data.Itemrefresh.Count)];
DataManager.SetDStore(id,rID);
var dataRandom = JsonTab.Instance.tables.StoreRandom.Get(rID);
var dis = data.Discountweight.Sum();
var r = Random.Range(0, dis);
for (var i = 0; i < dataRandom.Discountweight.Count; i++)
{
r -= dataRandom.Discountweight[i];
if (r > 0) continue;
DataManager.SetDDiscount(id,dataRandom.Discount[i]);
break;
}
}
public void OpenRewardPanel(List<ItemDataNum> itemDatas)
{
_panel.gameObject.SetActive(true);
_panel.SaveData(itemDatas);
}
}