using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using Unity.VisualScripting.Antlr3.Runtime; using UnityEngine; using UnityEngine.UI; public class BettingBtn : MonoBehaviour { public PlayerInfo playerCoinUpdate;//用于每次下注后更新左上角金币数 public static BettingBtn instance; public GameObject BetList; public Button NumBtn; public Text BetText; public float BetValue;//投注的值 public float AllBetValue;//投注总值 public Button BetButton;//投注的按钮 public GameObject text1; public GameObject text2; public GameObject text3; public GameObject text4; public GameObject text5; public GameObject text6; public List list=new List(); public TextMeshProUGUI SelfWoniuText; public bool SuccessBet;//是否成功下注 // Start is called before the first frame update void Start() { instance = this; BetList.SetActive(false); NumBtn.onClick.AddListener(OnClickNumBtn); BetValue = 50;//默认50 SetBet(); } void OnClickNumBtn() { BetList.SetActive(true); } [System.Serializable] public class RequestData { public int userId; public int escapeId; public float bet; public int roomNo; } public GameObject bg; public async void OnClickBetBtnAsync() { // bg.GetComponentInChildren().battleRoyaleGameDetails(); RequestData body = new RequestData(); body.escapeId = bg.GetComponentInChildren().escapeId; body.bet = BetValue; body.roomNo = bg.GetComponentInChildren().roomNo; body.userId = Global.global.serverResponse.data.userId; //Debug.Log(bg.GetComponentInChildren().house); //bg.GetComponentInChildren().house.text.GetComponent().AddText(BetValue); string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders()); Debug.Log("用户下注响应: " + response+"|||||"+"请求参数:escapeId"+ body.escapeId+" bet:"+ body.bet+ " roomNo:"+ body.roomNo+" userId:"+ body.userId); ServerResponse513 serverResponse_513 = JsonConvert.DeserializeObject(response); if (serverResponse_513.code==200) { bg.GetComponentInChildren().ReHouseText();//5.1.2 StartCoroutine(Tools.AnimateTextMashPro(PlayerInfo.instance.AllBetCoins, PlayerInfo.instance.AllBetCoins + BetValue, 0.5f, SelfWoniuText));//修改蜗牛头上文本 PlayerInfo.instance.AllBetCoins += BetValue; PlayerInfo.instance.HaveBet = true; //调用玩家信息,更新左上角蜗蛋数量 playerCoinUpdate.QueryPlayerInfo(); Debug.Log("-------投注成功-------"); Promptmgr.Instance.PromptBubble(serverResponse_513.message); } else { Debug.Log("-------投注失败-------"); Promptmgr.Instance.PromptBubble(serverResponse_513.message); } Debug.Log("点击了下注按钮================================================" + playerCoinUpdate.Money); } public async void BetAgain(Action onComplete=null) { //bg.GetComponentInChildren().battleRoyaleGameDetails(); RequestData body = new RequestData(); body.escapeId = bg.GetComponentInChildren().escapeId; //body.bet = PlayerInfo.instance.AllBetCoins; body.bet = 0; body.roomNo = bg.GetComponentInChildren().roomNo; body.userId = Global.global.serverResponse.data.userId; string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders()); Debug.Log("用户切换下注响应: " + response + "|||||" + "请求参数:escapeId" + body.escapeId + " bet:" + body.bet + " roomNo:" + body.roomNo + " userId:" + body.userId); ServerResponse513 serverResponse_513 = JsonConvert.DeserializeObject(response); if (serverResponse_513.code == 200) { Debug.Log("-------切换投注成功-------"); Promptmgr.Instance.PromptBubble(serverResponse_513.message); onComplete?.Invoke(); bg.GetComponentInChildren().ReHouseText();//5.1.2 } else { Promptmgr.Instance.PromptBubble(serverResponse_513.message); Debug.Log("-------切换投注失败-------"); } } void SetBet() { // 获取所有的Button组件 Button[] buttons = BetList.GetComponentsInChildren