116 lines
3.0 KiB
C#
116 lines
3.0 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
public class Lottery : MonoBehaviour
|
||
{
|
||
public GameObject LotteryPanel;
|
||
public Button LotteryBtn;
|
||
|
||
public GameObject petItem;
|
||
public Transform Connect;
|
||
|
||
public List<Sprite> petsp = new List<Sprite>();
|
||
public List<PetFightingBtn> fightinglist = new List<PetFightingBtn>();
|
||
public Button ClosefightingBtn;
|
||
|
||
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);
|
||
}
|
||
}
|
||
|
||
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);
|
||
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;
|
||
fightinglist.Add(obj.GetComponent<PetCard>().petFightingBtn);
|
||
}
|
||
}
|
||
|
||
Sprite showSprite(string n)
|
||
{
|
||
|
||
switch (n)
|
||
{
|
||
case "鼠":
|
||
return petsp[0];
|
||
break;
|
||
case "牛":
|
||
return petsp[1];
|
||
break;
|
||
case "虎":
|
||
return petsp[2];
|
||
break;
|
||
case "兔":
|
||
return petsp[3];
|
||
break;
|
||
case "龙":
|
||
return petsp[4];
|
||
break;
|
||
case "蛇":
|
||
return petsp[5];
|
||
break;
|
||
case "马":
|
||
return petsp[6];
|
||
break;
|
||
case "羊":
|
||
return petsp[7];
|
||
break;
|
||
case "猴":
|
||
return petsp[8];
|
||
break;
|
||
case "鸡":
|
||
return petsp[9];
|
||
break;
|
||
case "狗":
|
||
return petsp[10];
|
||
break;
|
||
case "猪":
|
||
return petsp[11];
|
||
break;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
|
||
async void LotteryClick()
|
||
{
|
||
PetAdoptResponse response = await Scene_main_jiekou.instance.PetAdopts();
|
||
if (response.code == 200)
|
||
{
|
||
Update_itemClick();
|
||
TreeInfo info = await Scene_main_jiekou.instance.TreeInfoS();
|
||
WaterPanel.instance.Updated_water(info);
|
||
|
||
Debug.Log(response);
|
||
}
|
||
else
|
||
{
|
||
Promptmgr.Instance.PromptBubble("水滴余额不足");
|
||
}
|
||
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
}
|