using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.UIElements; using static input_box_pop_up_window; [Serializable] public class RootObject { public List List; public int ErrorCode; public string ErrorMessage; } public class JinShaBuy : mount { public int number=1; public int max = 10; public int minerjiage = 0; public List rooms; public override void Awake() { } public void Show_buy(Sprite minerIcon,string minerName,int CurrencyId,int Num,float minerjiage,bool isMinr=true)//购买弹窗 { if (float.Parse(AssestPanel.instance.Coin.text) boxTypes = new List(); boxTypes.Add(new BoxType { Name = "account_number", textName = "道具兑换道具", Type = 10, is_required = false, icon = LoadSprite(mount.mountitem.itemDataList[CurrencyId].IconPath), icon2 = minerIcon, nametext1 = "金币", nametext2 = minerName, numbertext1 = "1",//单个矿工的价钱 numbertext2 = number.ToString()//几个矿工 }); boxTypes.Add(new BoxType { Name = "account_number", textName = " 数量:", prompt = "请输入购买数量", Type = 6, is_required = false}); boxTypes.Add(new BoxType { Name = "submit", textName = " 取消购买 ", Type = 2 }); GameObject gameObject = add_pop_up(true);//生成弹窗母体 gameObject.GetComponent().minHeight = 800;//设置最低高度 List gameObjects = gameObject.GetComponent().updateUI(boxTypes, "购买");//测试输入框回调处理 //初始化 number = 1; this.minerjiage = (int)minerjiage; max = (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage)>10?10: (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage); //max = int.Parse(AssestPanel.instance.Coin.text) / this.minerjiage; gameObjects[0].GetComponent().numbertextobj1.GetComponent().text = (this.minerjiage * number).ToString(); gameObjects[0].GetComponent().numbertextobj2.GetComponent().text = number.ToString(); UpdateText(gameObjects[1].GetComponent().contentobj.GetComponent()); UpdateText(gameObjects[1].GetComponent().contentobj.GetComponent()); gameObjects[1].GetComponent().register_click(async (BoxType boxType, int type) =>//登录确定或取消 { if (type == 0) { if (number>1) { number--; max = (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage); gameObjects[0].GetComponent().numbertextobj1.GetComponent().text = (this.minerjiage*number).ToString(); gameObjects[0].GetComponent().numbertextobj2.GetComponent().text = number.ToString(); UpdateText(gameObjects[1].GetComponent().contentobj.GetComponent()); } } else if (type == 1) { if (number < max) { number++; max = (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage); gameObjects[0].GetComponent().numbertextobj1.GetComponent().text = (this.minerjiage * number).ToString(); gameObjects[0].GetComponent().numbertextobj2.GetComponent().text = number.ToString(); UpdateText(gameObjects[1].GetComponent().contentobj.GetComponent()); } } else if (type == 2) { if (number!= max) { number=max; max = (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(AssestPanel.instance.Coin.text) / minerjiage); gameObjects[0].GetComponent().numbertextobj1.GetComponent().text = (this.minerjiage * number).ToString(); gameObjects[0].GetComponent().numbertextobj2.GetComponent().text = number.ToString(); UpdateText(gameObjects[1].GetComponent().contentobj.GetComponent()); } } }); gameObjects[2].GetComponent().register_click(async (BoxType boxType, int type) =>//登录确定或取消 { if (type == 0) { gameObject.GetComponent().destroy(); } else if (type == 1) { if (isMinr) { GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // 购买矿工 generateForFisherElf.Num = Num; generateForFisherElf.Count = Convert.ToInt32(number); string response = await web.SendRequest(web.URL + "/Voucher/GenerateForMinerElf", "POST", JsonUtility.ToJson(generateForFisherElf)); Mining_Wizard_ID data = JsonUtility.FromJson(response); Debug.Log("购买对象的id"+data.Ids[0]); Promptmgr.Instance.PromptBubble("购买精灵成功", Color.black,Color.blue); int index1 = Num - 1; int index2 = (Num - 1)*2; rooms[index1].GetComponent().addman(index2, number); Debug.Log(data.Ids[0]); rooms[index1].GetComponent().ids.Add(data.Ids[0]); } else { ItmeBuy itmebuy = new ItmeBuy(); itmebuy.Num = Num; itmebuy.Count = Convert.ToInt32(number); itmebuy.Type = 1; string response = await web.SendRequest(web.URL + "/Item/Buy", "POST", JsonUtility.ToJson(itmebuy)); Debug.Log(response); Promptmgr.Instance.PromptBubble("购买设备成功", Color.black, Color.blue); int index1 = Num - 74; int index2 = (Num - 74)*2; rooms[index1].GetComponent().addtools(index2, number); } } }); } void UpdateText(Text text) { text.text = number.ToString(); } }