120 lines
3.4 KiB
C#
120 lines
3.4 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;
|
|
[SerializeField] private Text _goldNum;
|
|
[SerializeField] private Text _diamondNum;
|
|
[SerializeField] private Text _physicalNum;
|
|
|
|
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);
|
|
ResetGold();
|
|
}
|
|
|
|
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);
|
|
ResetGold();
|
|
}
|
|
|
|
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);
|
|
foreach (var s in dayStoreItems)
|
|
{
|
|
s.ResetItem();
|
|
}
|
|
|
|
ResetGold();
|
|
}
|
|
public void ResetGold()
|
|
{
|
|
_goldNum.text = DataManager.GetItem(2).ToString();
|
|
_diamondNum.text = DataManager.GetItem(3).ToString();
|
|
_physicalNum.text=DataManager.GetPhysical().ToString();
|
|
}
|
|
}
|