From fa5115118570225f4688a9bb5e2f2624fe416137 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Mon, 18 Nov 2024 18:52:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scenes/Battle_Royale.unity | 2 ++ .../Scripts/Battle_Royale/AllHouseContro.cs | 4 ++- .../Scripts/Battle_Royale/BettingBtn.cs | 5 +++ .../Scripts/Battle_Royale/PlayerInfo.cs | 35 +++++++++++++++++-- .../Assets/Scripts/Login/Global.cs | 29 +++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity index 7d18ab8..e18da24 100644 --- a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity +++ b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity @@ -1777,6 +1777,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 06037c1fbc8038e4eb2bf05d1c29291e, type: 3} m_Name: m_EditorClassIdentifier: + settlementCoinUpdate: {fileID: 177818109} HouseBtnList: - {fileID: 898215879} - {fileID: 2143530050} @@ -8678,6 +8679,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4fb563e68ba8d9747a0dc8bd431d8495, type: 3} m_Name: m_EditorClassIdentifier: + playerCoinUpdate: {fileID: 177818109} BetList: {fileID: 1737087529} NumBtn: {fileID: 1954526986} BetText: {fileID: 251123273} diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs index 6e25f4b..8a580f1 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs @@ -11,6 +11,7 @@ using static UnityEngine.UIElements.UxmlAttributeDescription; public class AllHouseContro : MonoBehaviour { + public PlayerInfo settlementCoinUpdate;//结算后更新左上角玩家金币数字=================================================================== public List HouseBtnList=new List(); public int roomNo = -1; public int escapeId = -1; @@ -202,7 +203,8 @@ public class AllHouseContro : MonoBehaviour BoosReturn(); break; } - + settlementCoinUpdate.QueryPlayerInfo(); + Debug.Log("结算后更新左上角玩家蜗蛋数量:===============================================" + settlementCoinUpdate.Money); } } } diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs index 7d3b95d..eb51551 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs @@ -10,6 +10,7 @@ using static UnityEditor.PlayerSettings; public class BettingBtn : MonoBehaviour { + public PlayerInfo playerCoinUpdate;//用于每次下注后更新左上角金币数 public static BettingBtn instance; public GameObject BetList; public Button NumBtn; @@ -68,6 +69,10 @@ public class BettingBtn : MonoBehaviour string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders()); Debug.Log("用户下注响应: " + response); bg.GetComponentInChildren().battleRoyaleGameDetails(); + + //调用玩家信息,更新左上角蜗蛋数量 + playerCoinUpdate.QueryPlayerInfo(); + Debug.Log("点击了下注按钮================================================" + playerCoinUpdate.Money); } public async void BetAgain() diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/PlayerInfo.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/PlayerInfo.cs index b9b78f0..daf7683 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/PlayerInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/PlayerInfo.cs @@ -1,12 +1,13 @@ +using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; - +using System.Threading.Tasks; public class PlayerInfo : MonoBehaviour { public static PlayerInfo instance; - + public static UserInfomation14 userInfomation14; public float Money = 1000; public float AllBetCoins;//总共下注蛋 public TextMeshProUGUI SelfWoniuText;//蜗牛下注显示文本 @@ -16,6 +17,7 @@ public class PlayerInfo : MonoBehaviour { instance = this; EggNum.instance.eggNumText.text=Money.ToString(); + QueryPlayerInfo(); } public bool SetMoney(float add) @@ -35,6 +37,33 @@ public class PlayerInfo : MonoBehaviour // Update is called once per frame void Update() { - + if (userInfomation14 != null) + { + Money = userInfomation14.data.beansCoin; + EggNum.instance.eggNumText.text = Money.ToString(); + } + } + // 查询玩家信息 + public async Task QueryPlayerInfo() // 5.1.1 + { + // 准备请求的头部信息,包含授权令牌 + Dictionary head14 = new Dictionary + { + { "Authorization", Global.global.serverResponse.data.token } + }; + + // 异步查询玩家信息 + string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14); + Debug.Log("1.4查询玩家信息" + response14); + userInfomation14 = JsonConvert.DeserializeObject(response14); + Debug.Log("玩家剩余蜗蛋:" + userInfomation14.data.beansCoin); + //Money = userInfomation14.beansCoin; + + // 解析服务器返回的数据 + Global.global.response = JsonConvert.DeserializeObject(response14); + + // 不需要返回值,只需表示异步操作完成 + await Task.CompletedTask; // 或者直接返回,不使用 await } } + diff --git a/TheStrongestSnail/Assets/Scripts/Login/Global.cs b/TheStrongestSnail/Assets/Scripts/Login/Global.cs index b03477d..2bfb517 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/Global.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/Global.cs @@ -137,3 +137,32 @@ public class GameEscapeModel public float beansCoinDivide; // 分成豆币 } +//玩家信息 +[Serializable] +public class UserInfomation14 +{ + public UserInfomation14Data data; +} +[Serializable] +public class UserInfomation14Data +{ + public int userId;//id + public int userName;//用户名(电话) + public string token; + public string nickName;//昵称 + public string headImg;//头像 + public int gender;//性别,1男2女 + public string birthday;//出生,"yyyy-MM-dd HH:mm:ss" + public float voluteCoin;//蜗壳 + public float beansCoin;//蜗蛋 + public float ichorCoin;//灵液 + public string idCard;//========================= + public string inviteCodeMy;//============= + public string inviteCodeBind;//========== + public string bindTime;//=========== + public int station;//========= + public string cuteNo;//靓号 + public string menberTime;//=============== + public bool isMember; + //public int cuteNo;//靓号 +} \ No newline at end of file