136 lines
3.9 KiB
C#
136 lines
3.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
public class Lottery : MonoBehaviour
|
||
{
|
||
public GameObject LotteryPanel;
|
||
public Button LotteryBtn;
|
||
|
||
public GameObject petItem;
|
||
public Transform Connect;
|
||
public Text WaterText;
|
||
|
||
public List<Sprite> petsp = new List<Sprite>();
|
||
public List<PetFightingBtn> fightinglist = new List<PetFightingBtn>();
|
||
public List<GameObject> ExuExhibitmusklist = new List<GameObject>();
|
||
|
||
public Button ClosefightingBtn;
|
||
public List<GameObject> objitem = new List<GameObject>();
|
||
public List<string> shenxiaocard = new List<string>();
|
||
|
||
async void OnEnable()
|
||
{
|
||
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
|
||
WaterText.text = info.Data.Water.ToString();
|
||
Update_itemClick();
|
||
}
|
||
|
||
|
||
async void Start()
|
||
{
|
||
LotteryBtn.onClick.AddListener(LotteryClick);
|
||
ClosefightingBtn.onClick.AddListener(CloseBtnClick);
|
||
|
||
|
||
}
|
||
|
||
public void CloseBtnClick()//隐藏所有展示item的btn
|
||
{
|
||
foreach (PetFightingBtn btn in fightinglist)
|
||
{
|
||
btn.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
public void Closemusk()//隐藏所有展示的musk
|
||
{
|
||
foreach (GameObject obj in ExuExhibitmusklist)
|
||
{
|
||
obj.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
async void Update_itemClick()
|
||
{
|
||
PetHome info = await Scene_main_jiekou.instance.getPetHomes();
|
||
for (int i = 0; i < info.data.items.Count; i++)//给宠物卡片的item传输id,名字,头像以及将动态生成的卡片的隐藏的方法传过去
|
||
{
|
||
GameObject obj = GameObject.Instantiate(petItem, Connect);
|
||
objitem.Add(obj);
|
||
|
||
obj.GetComponent<PetCard>().petName.text = info.data.items[i].name;
|
||
obj.GetComponent<PetCard>().petFightingBtn.id = info.data.items[i].id;
|
||
obj.GetComponent<PetCard>().petimage.sprite = showSprite(info.data.items[i].name);
|
||
obj.GetComponent<PetCard>().petFightingBtn.lottery = this;
|
||
obj.GetComponent<PetCard>().petFightingBtn.Exhibitmusk = obj.GetComponent<PetCard>().Exhibitmusk;
|
||
fightinglist.Add(obj.GetComponent<PetCard>().petFightingBtn);
|
||
ExuExhibitmusklist.Add(obj.GetComponent<PetCard>().Exhibitmusk);
|
||
if (info.data.items[i].battles_status == 1)
|
||
{
|
||
obj.GetComponent<PetCard>().petFightingBtn.Exhibitmusk.SetActive(true);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
Sprite showSprite(string n)
|
||
{
|
||
for (int i = 0; i < shenxiaocard.Count; i++)
|
||
{
|
||
if (shenxiaocard[i].Equals(n))
|
||
{
|
||
return petsp[i];
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
|
||
async void LotteryClick()
|
||
{
|
||
PetAdoptResponse response = await Scene_main_jiekou.instance.PetAdopts();
|
||
if (response.code == 200)
|
||
{
|
||
foreach (GameObject ob in objitem)
|
||
{
|
||
Destroy(ob);
|
||
}
|
||
objitem.Clear();
|
||
fightinglist.Clear();
|
||
foreach (GameObject obj in ExuExhibitmusklist)
|
||
{
|
||
Destroy(obj);
|
||
}
|
||
ExuExhibitmusklist.Clear();
|
||
Update_itemClick();
|
||
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
|
||
WaterText.text = info.Data.Water.ToString();
|
||
WaterPanel.instance.Updated_water();
|
||
Debug.Log(response);
|
||
}
|
||
else
|
||
{
|
||
Promptmgr.Instance.PromptBubble("水滴余额不足");
|
||
}
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
foreach (GameObject ob in objitem)
|
||
{
|
||
Destroy(ob);
|
||
}
|
||
objitem.Clear();
|
||
foreach (GameObject obj in ExuExhibitmusklist)
|
||
{
|
||
Destroy(obj);
|
||
}
|
||
ExuExhibitmusklist.Clear();
|
||
fightinglist.Clear();
|
||
}
|
||
// Update is called once per frame
|
||
|
||
}
|