Cute_demon_attacks/meng_yao/Assets/script/TanChuang/Lottery.cs

103 lines
2.9 KiB
C#
Raw Normal View History

2024-11-14 16:05:27 +08:00
using System.Collections;
using System.Collections.Generic;
2024-12-25 23:35:36 +08:00
using Unity.VisualScripting;
2024-11-14 16:05:27 +08:00
using UnityEngine;
using UnityEngine.UI;
public class Lottery : MonoBehaviour
{
public GameObject LotteryPanel;
public Button LotteryBtn;
public GameObject petItem;
public Transform Connect;
2024-12-25 23:35:36 +08:00
public Text WaterText;
public List<Sprite> petsp = new List<Sprite>();
2024-12-25 21:48:50 +08:00
public List<PetFightingBtn> fightinglist = new List<PetFightingBtn>();
public Button ClosefightingBtn;
2024-12-25 23:35:36 +08:00
public List<GameObject> objitem = new List<GameObject>();
2024-12-30 14:12:56 +08:00
public List<string> shenxiaocard = new List<string>();
async void OnEnable()
2024-12-25 23:35:36 +08:00
{
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
WaterText.text = info.Data.Water.ToString();
}
2024-12-25 21:48:50 +08:00
async void Start()
2024-11-14 16:05:27 +08:00
{
2024-11-14 16:15:28 +08:00
LotteryBtn.onClick.AddListener(LotteryClick);
2024-12-25 21:48:50 +08:00
ClosefightingBtn.onClick.AddListener(CloseBtnClick);
Update_itemClick();
2024-12-25 23:35:36 +08:00
}
2024-12-25 21:48:50 +08:00
public void CloseBtnClick()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʾitem<65><6D>btn
{
foreach (PetFightingBtn btn in fightinglist)
{
btn.gameObject.SetActive(false);
}
}
async void Update_itemClick()
{
PetHome info = await Scene_main_jiekou.instance.getPetHomes();
2024-12-25 21:48:50 +08:00
for (int i = 0; i < info.data.items.Count; i++)//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƭ<EFBFA8><C6AC>item<65><6D><EFBFBD><EFBFBD>id<69><64><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>ɵĿ<C9B5>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD>صķ<D8B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ
{
GameObject obj = GameObject.Instantiate(petItem, Connect);
2024-12-25 23:35:36 +08:00
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);
2024-12-25 21:48:50 +08:00
obj.GetComponent<PetCard>().petFightingBtn.lottery = this;
fightinglist.Add(obj.GetComponent<PetCard>().petFightingBtn);
}
2024-12-25 23:35:36 +08:00
2024-11-14 16:15:28 +08:00
}
Sprite showSprite(string n)
{
2024-12-30 14:12:56 +08:00
for (int i = 0; i < shenxiaocard.Count; i++)
{
2024-12-30 14:36:08 +08:00
if (shenxiaocard[i].Equals(n))
2024-12-30 14:12:56 +08:00
{
return petsp[i];
}
}
return null;
2024-12-30 14:12:56 +08:00
}
async void LotteryClick()
2024-11-14 17:23:08 +08:00
{
PetAdoptResponse response = await Scene_main_jiekou.instance.PetAdopts();
if (response.code == 200)
{
2024-12-25 23:35:36 +08:00
foreach (GameObject ob in objitem)
{
Destroy(ob);
}
objitem.Clear();
fightinglist.Clear();
Update_itemClick();
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
2024-12-25 23:35:36 +08:00
WaterText.text = info.Data.Water.ToString();
WaterPanel.instance.Updated_water(info);
Debug.Log(response);
}
else
{
Promptmgr.Instance.PromptBubble(<><CBAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB2BB>");
}
2024-11-14 16:05:27 +08:00
}
// Update is called once per frame
void Update()
{
}
}