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 petsp = new List(); public List fightinglist = new List(); public List ExuExhibitmusklist = new List(); public Button ClosefightingBtn; public List objitem = new List(); public List shenxiaocard = new List(); async void OnEnable() { TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS(); WaterText.text = info.Data.Water.ToString(); } async void Start() { LotteryBtn.onClick.AddListener(LotteryClick); ClosefightingBtn.onClick.AddListener(CloseBtnClick); Update_itemClick(); } 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().petName.text = info.data.items[i].name; obj.GetComponent().petFightingBtn.id = info.data.items[i].id; obj.GetComponent().petimage.sprite = showSprite(info.data.items[i].name); obj.GetComponent().petFightingBtn.lottery = this; obj.GetComponent().petFightingBtn.Exhibitmusk = obj.GetComponent().Exhibitmusk; fightinglist.Add(obj.GetComponent().petFightingBtn); ExuExhibitmusklist.Add(obj.GetComponent().Exhibitmusk); if (info.data.items[i].battles_status == 1) { obj.GetComponent().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(); Update_itemClick(); TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS(); WaterText.text = info.Data.Water.ToString(); WaterPanel.instance.Updated_water(info); Debug.Log(response); } else { Promptmgr.Instance.PromptBubble("水滴余额不足"); } } // Update is called once per frame void Update() { } }