diff --git a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity index 5c77109..7de6c0e 100644 --- a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity +++ b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity @@ -957,6 +957,7 @@ GameObject: - component: {fileID: 142654720} - component: {fileID: 142654722} - component: {fileID: 142654723} + - component: {fileID: 142654724} m_Layer: 5 m_Name: Bg m_TagString: Untagged @@ -1085,6 +1086,20 @@ MonoBehaviour: - {fileID: 715869104} - {fileID: 1049673032} - {fileID: 708679840} +--- !u!114 &142654724 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 142654718} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3} + m_Name: + m_EditorClassIdentifier: + m_AspectMode: 1 + m_AspectRatio: 0.5632184 --- !u!1 &157655806 GameObject: m_ObjectHideFlags: 0 @@ -2257,7 +2272,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.93435806} m_AnchorMax: {x: 0.2895423, y: 0.98676854} - m_AnchoredPosition: {x: 1.2630615, y: 0} + m_AnchoredPosition: {x: 1.2629395, y: 0} m_SizeDelta: {x: 2.5264893, y: -2.3384018} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &332149379 @@ -3449,7 +3464,7 @@ MonoBehaviour: m_EditorClassIdentifier: panel: {fileID: 0} canvasGroup: {fileID: 0} - ReturnBtn: {fileID: 0} + ReturnBtn: {fileID: 470934207} moveObject: {fileID: 177818102} --- !u!1 &632503723 GameObject: @@ -10655,6 +10670,7 @@ MonoBehaviour: IsLeft: 0 HouseId: 0 BoosHouse: {fileID: 0} + allHouseContro: {fileID: 0} --- !u!114 &1790882392 MonoBehaviour: m_ObjectHideFlags: 0 @@ -12298,17 +12314,23 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2127674356} - - component: {fileID: 2127674357} - component: {fileID: 2127674358} - - component: {fileID: 2127674360} - component: {fileID: 2127674361} + - component: {fileID: 2127674362} + - component: {fileID: 2127674369} + - component: {fileID: 2127674368} + - component: {fileID: 2127674367} + - component: {fileID: 2127674366} + - component: {fileID: 2127674365} + - component: {fileID: 2127674364} + - component: {fileID: 2127674363} m_Layer: 5 m_Name: InfoObject m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &2127674356 RectTransform: m_ObjectHideFlags: 0 @@ -12329,21 +12351,6 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &2127674357 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2127674355} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 48ec9b444797b3d4d93d6d2c1bb4299b, type: 3} - m_Name: - m_EditorClassIdentifier: - token: - updateUserInfo: {fileID: 0} - sec: 0 --- !u!114 &2127674358 MonoBehaviour: m_ObjectHideFlags: 0 @@ -12356,20 +12363,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &2127674360 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2127674355} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9e50b3d02b729854e87c092afffd2a03, type: 3} - m_Name: - m_EditorClassIdentifier: - token: - escapeId: -1 --- !u!114 &2127674361 MonoBehaviour: m_ObjectHideFlags: 0 @@ -12384,6 +12377,175 @@ MonoBehaviour: m_EditorClassIdentifier: gameEscapeId: 0 carrySeconds: 0 + gameNo: + demonMode: 0 + startTime: + betTime: + countTime: + settleTime: + status: 0 + roomNoKill: + roomNoRemain: + beansCoinAll: 0 + beansCoinKill: 0 + beansCoinRemain: 0 + beansCoinFee: 0 + beansCoinRank: 0 + beansCoinDivide: 0 + escapeId: 0 + roomNo: 0 + roomBeansCoin: 0 +--- !u!114 &2127674362 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c1d71841b9c8a8242a6b75a267015171, type: 3} + m_Name: + m_EditorClassIdentifier: + HousePur: {fileID: 1049673032} + HouseLan: {fileID: 898215879} + HouseQin: {fileID: 708679840} + HouseLu: {fileID: 2143530050} + HouseHuang: {fileID: 20259221} + HouseFen: {fileID: 715869104} +--- !u!114 &2127674363 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e57021e815a075842afcb8cea3c745d1, type: 3} + m_Name: + m_EditorClassIdentifier: + token: + escapeId: -1 + userId: 0 + code: 0 + message: + roomNoKill: 0 + roomNoRemain: 0 +--- !u!114 &2127674364 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3e317c8c24b13004bb49858be0928128, type: 3} + m_Name: + m_EditorClassIdentifier: + token: + escapeId: -1 + code: 0 + message: + data: 0 + updateUserInfoButton: {fileID: 0} +--- !u!114 &2127674365 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 81202125ae1fe2f43a0ccf3e996186bf, type: 3} + m_Name: + m_EditorClassIdentifier: + token: + escapeId: -1 + code: 0 + message: + userId: 0 + userName: + nickName: + headImg: + gender: 0 + birthday: + voluteCoin: 0 + beansCoin: 0 + ichorCoin: 0 + cuteNo: 0 + selectUserInfoButton: {fileID: 0} +--- !u!114 &2127674366 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c230883956c0b3546a885c300ad34498, type: 3} + m_Name: + m_EditorClassIdentifier: + token: + escapeId: -1 + userId: 0 + latestCode: 0 + latestMessage: + latestRoomNoKill: 0 + latestRoomNoRemain: 0 + queryKillButton: {fileID: 0} +--- !u!114 &2127674367 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b27d2d49f51751e42b31653d0b0b8d2d, type: 3} + m_Name: + m_EditorClassIdentifier: + latestEscapeId: 0 + latestRoomNo: 0 + latestRoomBeansCoin: 0 + token: + escapeId: -1 + userId: 0 + lastEscapeRoomResponse: +--- !u!114 &2127674368 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e8d2e3fe1964bd34f8d61e48e533c393, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &2127674369 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127674355} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 265365642b7b8644081cd2ce79416fb3, type: 3} + m_Name: + m_EditorClassIdentifier: + token: + escapeId: -1 + userId: 0 + code: 0 + message: + userBetButton: {fileID: 0} --- !u!1 &2135586305 GameObject: m_ObjectHideFlags: 0 diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/BossContro.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/BossContro.cs index a8ad043..3a5b7d8 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/BossContro.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/BossContro.cs @@ -16,6 +16,7 @@ public class BossContro : MonoBehaviour public int HouseId;//房间编号 public Transform BoosHouse;//boos房间 + public AllHouseContro allHouseContro; // Start is called before the first frame update void Start() { @@ -76,9 +77,10 @@ public class BossContro : MonoBehaviour break; } //MoveParent(); - Tools.MoveUpOrDwon(transform.parent.GetComponent().door, 270, () => { - BossAni.SetInteger("State", 1); // 动画转为移动 + BossAni.SetInteger("State", 1); // 动画转为移动 GetComponent().StartMove(); // 开始移动 - }); + //Tools.MoveUpOrDwon(transform.parent.GetComponent().door, 270, () => { + + //}); } } diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/FailPanel.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/FailPanel.cs index 3445e93..97e0001 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/FailPanel.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/FailPanel.cs @@ -26,7 +26,7 @@ public class FailPanel : BasePanel { base.HidePanel(); PlayerMovePos.instance.IsReturn = true; - BossContro.instance.ReturnParent(); + //BossContro.instance.ReturnParent(); MaskContro.instance.SetMask(false); //都返回原来的位置 } diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs index c7ffc88..db974c3 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs @@ -15,8 +15,8 @@ public class HegemonTime : MonoBehaviour void Start() { instance = this; - timeNum = 10; - StartCoroutine(StartGame()); + + //StartCoroutine(StartGame()); } @@ -34,9 +34,9 @@ public class HegemonTime : MonoBehaviour timeText.text = (timeNum-carrySeconds).ToString(); // 显示整数秒数 yield return new WaitForSeconds(1f); // 等待1秒 - timeNum -= 1; + //timeNum -= 1; - if (timeNum==5) + if (timeNum==20) { allHouseContro.ControAllDoorClose(); MaskContro.instance.SetMask(true); @@ -46,7 +46,11 @@ public class HegemonTime : MonoBehaviour Debug.Log("Boos来了"); BossContro.instance.BossMove(); - timeNum = 10; + //timeNum = 60; + } + public void HadInfAndStartGame()//启动倒计时 + { + timeNum=60-InfoObject.GetComponent().carrySeconds; + StartCoroutine(StartGame()); } - } diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/MoneyAnimation.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/MoneyAnimation.cs index 41cb709..0c28981 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/MoneyAnimation.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/MoneyAnimation.cs @@ -23,6 +23,7 @@ public class MoneyAnimation : MonoBehaviour public void PlayCoinAnimation() { + coins.Clear(); int completedCount = 0; // 记录已经完成动画的金币数量 // 确保目标点数组有至少 1 个元素 @@ -84,22 +85,25 @@ public class MoneyAnimation : MonoBehaviour Random.Range(-randomTargetRadius, randomTargetRadius), 0); - // 使用 DOTween 移动金币到随机的目标点附近 - coin.transform.DOMove(randomTargetPosition, moveDuration) - .SetDelay(delay) // 只有延迟,但不需要等前一个金币完成 - .SetEase(Ease.InOutQuad) // 设置缓动类型 - .OnComplete(() => - { - completedCount++; - Destroy(coin); // 动画完成后销毁金币 - - // 当所有金币都完成动画时,执行其他操作 - if (completedCount == coinCount) + if (coin != null) + { + // 使用 DOTween 移动金币到随机的目标点附近 + coin.transform.DOMove(randomTargetPosition, moveDuration) + .SetDelay(delay) // 只有延迟,但不需要等前一个金币完成 + .SetEase(Ease.InOutQuad) // 设置缓动类型 + .OnComplete(() => { - // 在所有金币完成后执行你需要的操作,比如: - // BettingBtn.instance.GiveMoney(); - } - }); + completedCount++; + Destroy(coin); // 动画完成后销毁金币 + + // 当所有金币都完成动画时,执行其他操作 + if (completedCount == coinCount) + { + // 在所有金币完成后执行你需要的操作,比如: + // BettingBtn.instance.GiveMoney(); + } + }); + } } } } diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs new file mode 100644 index 0000000..3200552 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RoomInfo : MonoBehaviour +{ + public static RoomInfo instance; + public HouseBtn HousePur; + public HouseBtn HouseLan; + public HouseBtn HouseQin; + public HouseBtn HouseLu; + public HouseBtn HouseHuang; + public HouseBtn HouseFen; + // Start is called before the first frame update + void Awake() + { + instance = this; + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs.meta b/TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs.meta similarity index 83% rename from TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs.meta rename to TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs.meta index b836a73..f1b76a0 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs.meta +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/RoomInfo.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 48ec9b444797b3d4d93d6d2c1bb4299b +guid: c1d71841b9c8a8242a6b75a267015171 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs deleted file mode 100644 index cb76057..0000000 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs +++ /dev/null @@ -1,110 +0,0 @@ -using JetBrains.Annotations; -using Newtonsoft.Json; -using System; -using System.Collections; -using System.Collections.Generic; -using Unity.VisualScripting.Antlr3.Runtime; -using UnityEngine; - -public class Test : MonoBehaviour -{ - public string token; - - // 当接收到 token 时触发此方法,仅保存 token - public void HandleTokenReceived(string receivedToken) - { - token = receivedToken; // 保存最新的 token - // 首次调用加载初始数据 - //LoadGameEscapeData(); - // Debug.Log("接收到新的 token: " + token); - } - - public UpdateUserInfo updateUserInfo; - public int sec; - // Start is called before the first frame update - void Start() - { - // 注册监听事件,当收到 token 时,触发 HandleTokenReceived - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - updateUserInfo = new UpdateUserInfo(); - } - - // Update is called once per frame - void Update() - { - TestButton(); - } - public async void TestButton() - { - if(Input.GetKey(KeyCode.X)) - { - sjdlkjf(); - //Debug.Log("nnnnnnnnnnnnnnnn"+sec); - } - } - - - public async void sjdlkjf() - { - // 用来给请求头赋值 - string Authorization = token; - //Debug.Log("Loding(Authorization)请求头赋值" + Authorization); - - // 5.1查询最近一场大屠杀 - Dictionary head51 = new Dictionary - { - { "Authorization", Authorization }, // 设置授权头 - }; - - string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51); - Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); // 查询最近一场大逃亡游戏详情: - - // 解析JSON数据 - string json = response51; - Response response = JsonConvert.DeserializeObject(json); - - int gameEscapeId = response.data.gameEscapeModel.id; - Debug.Log(gameEscapeId); - //Debug.Log("解析成功,id为: " + gameEscapeId); - - int carrySeconds = response.data.carrySeconds; - Debug.Log("====================================================================================="+carrySeconds); - - } - -} - - - - - - [Serializable] - public class GameEscapeModel - { - public int id; // 解析游戏ID - public string gameNo; // 包括游戏编号 - } - - //[Serializable] - //public class GameEscapeRoomResponseVo - //{ - // public int escapeId; // 逃脱游戏的ID - // public int roomNo; // 房间号 - //} - - [Serializable] - public class Data - { - public int carrySeconds; // 持续秒数 - public GameEscapeModel gameEscapeModel; // 嵌套的GameEscapeModel对象 - //public List gameEscapeRoomResponseVoList; // 房间信息列表 - public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义 - } - - [Serializable] - public class Response - { - public int code; // 状态码 - public string message; // 返回信息 - public Data data; // 数据对象 - } \ No newline at end of file diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs b/TheStrongestSnail/Assets/Scripts/Login/11/Gamber513.cs similarity index 76% rename from TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs rename to TheStrongestSnail/Assets/Scripts/Login/11/Gamber513.cs index 74f13bf..92ecb78 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/Gamber513.cs @@ -108,16 +108,40 @@ using UnityEngine.UI; } }*/ - -public class Gamber : MonoBehaviour +//解析+单例 +public class Gamber513 : MonoBehaviour { + // 单例模式实现 + public static Gamber513 Instance { get; private set; } + + // 全局变量,用于存储服务器返回的具体字段 public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + public int userId; // 用户 ID private string lastUserBetResponse = null; // 保存最新的用户下注响应 - // 假设有一个下注按钮==================================================================================================== + // 服务器返回的字段,作为全局变量 + public int code; // 返回状态码,例如 200 表示成功 + public string message; // 提示信息 + public object data; // 数据,可能为空 + + // 假设有一个下注按钮 public Button userBetButton; + void Awake() + { + // 实现单例模式 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁 + } + else + { + Destroy(gameObject); + } + } + void Start() { // 注册监听事件,当收到 token 时,触发 HandleTokenReceived @@ -126,7 +150,7 @@ public class Gamber : MonoBehaviour // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - // 假设下注按钮被点击时调用 OnUserBetButtonClicked=================================================================== + // 假设下注按钮被点击时调用 OnUserBetButtonClicked if (userBetButton != null) { userBetButton.onClick.AddListener(OnUserBetButtonClicked); @@ -148,9 +172,12 @@ public class Gamber : MonoBehaviour escapeId = newGameEscapeId; // 保存最新的 escapeId Debug.Log("接收到新的 GameEscapeId: " + escapeId); - // 在这里可以选择手动调用 UserBet(),例如 + // 在这里可以选择手动调用 UserBet() lastUserBetResponse = await UserBet(); Debug.Log("HandleGameEscapeIdUpdated 处理的 UserBet 响应: " + lastUserBetResponse); + + // 解析响应 + ParseUserBetResponse(lastUserBetResponse); } // 按钮点击后触发下注操作 @@ -169,12 +196,12 @@ public class Gamber : MonoBehaviour return; } - // 调用 UserBet 并保存响应//========================================================================================== + // 调用 UserBet 并保存响应 lastUserBetResponse = await UserBet(); Debug.Log("用户按钮触发的 UserBet 响应: " + lastUserBetResponse); - // 可以根据响应做进一步的处理 - HandleUserBetResponse(lastUserBetResponse); + // 解析响应 + ParseUserBetResponse(lastUserBetResponse); } // 用户下注方法 @@ -195,13 +222,13 @@ public class Gamber : MonoBehaviour var headers = CreateHeaders(); string body = $@" {{ - ""userId"": 106, + ""userId"": {userId}, ""escapeId"": {escapeId}, ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); return response; // 返回响应 } @@ -221,16 +248,38 @@ public class Gamber : MonoBehaviour }; } - // 处理 UserBet 方法的响应 - private void HandleUserBetResponse(string response) + // 处理 UserBet 方法的响应,并将解析后的字段保存到全局变量中 + private void ParseUserBetResponse(string response) { - if (response.Contains("success")) + if (string.IsNullOrEmpty(response)) { - Debug.Log("下注成功!"); + Debug.LogWarning("无法解析用户下注响应,响应为空。"); + return; } - else + + try { - Debug.LogWarning("下注失败,服务器响应: " + response); + // 使用 Newtonsoft.Json 解析响应 + UserBetResponse betResponse = JsonConvert.DeserializeObject(response); + + // 将解析后的数据赋值给全局变量 + code = betResponse.code; + message = betResponse.message; + data = betResponse.data; + + // 输出结果 + if (code == 200) + { + Debug.Log($"下注成功!消息: {message}"); + } + else + { + Debug.LogWarning($"下注失败,消息: {message}"); + } + } + catch (System.Exception e) + { + Debug.LogWarning("解析用户下注响应时出错: " + e.Message); } } @@ -240,7 +289,7 @@ public class Gamber : MonoBehaviour LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - // 取消按钮的点击监听================================================================================================ + // 取消按钮的点击监听 if (userBetButton != null) { userBetButton.onClick.RemoveListener(OnUserBetButtonClicked); @@ -258,5 +307,16 @@ public class Gamber : MonoBehaviour lastUserBetResponse = await UserBet(); // 调用 UserBet 并保存响应 Debug.Log("初始加载的 UserBet 响应: " + lastUserBetResponse); + + // 解析响应 + ParseUserBetResponse(lastUserBetResponse); } } + +// 用户下注响应数据类,用于存储解析后的响应数据 +public class UserBetResponse +{ + public int code { get; set; } // 返回状态码,例如 200 表示成功 + public string message { get; set; } // 提示信息 + public object data { get; set; } // 数据,可能为空 +} diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/Gamber513.cs.meta similarity index 100% rename from TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs.meta rename to TheStrongestSnail/Assets/Scripts/Login/11/Gamber513.cs.meta diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/QueryRoomdetails512.cs b/TheStrongestSnail/Assets/Scripts/Login/11/QueryRoomdetails512.cs index 5b0affb..5823f14 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/QueryRoomdetails512.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/QueryRoomdetails512.cs @@ -699,6 +699,7 @@ using UnityEngine.UI; } }*/ //解析+高频+单例 +//解析+单例 public class QueryRoomdetails512 : MonoBehaviour { // 单例实例 @@ -800,7 +801,7 @@ public class QueryRoomdetails512 : MonoBehaviour }}"; // Debug.Log("正在查询逃亡房间详情..."); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); Debug.Log("5.1.2查询逃亡房间详情响应: " + response); // 反序列化 JSON 数据为 ServerResponse 对象并处理响应 diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/SelectQueryKill514.cs b/TheStrongestSnail/Assets/Scripts/Login/11/SelectQueryKill514.cs index aa9d8a6..7bbd712 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/SelectQueryKill514.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/SelectQueryKill514.cs @@ -398,7 +398,7 @@ public class SelectQueryKill514 : MonoBehaviour }}"; Debug.Log("正在查询击杀信息..."); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", body, headers); Debug.Log("查询击杀信息响应: " + response); HandleQueryKillResponse(response); // 处理响应数据 return response; // 返回响应 diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs b/TheStrongestSnail/Assets/Scripts/Login/11/SelectUserInfo14.cs similarity index 75% rename from TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs rename to TheStrongestSnail/Assets/Scripts/Login/11/SelectUserInfo14.cs index 0065e3d..00db666 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/SelectUserInfo14.cs @@ -105,10 +105,7 @@ using Newtonsoft.Json.Linq; } }*/ - - - -/*public class SelectUserInfo : MonoBehaviour +/*public class SelectUserInfo14 : MonoBehaviour { public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 @@ -244,16 +241,49 @@ using Newtonsoft.Json.Linq; }*/ +//解析+单例 -public class SelectUserInfo : MonoBehaviour +public class SelectUserInfo14 : MonoBehaviour { + // 单例模式实现 + public static SelectUserInfo14 Instance { get; private set; } + + // 全局变量,用于存储服务器返回的具体字段 public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 private string lastSelectUserInfoResponse = null; // 保存最新的用户详情查询响应 - // 假设有一个手动查询用户详情的按钮======================================================================================= + // 服务器返回的字段,作为全局变量 + public int code; // 状态码,例如 200 表示成功 + public string message; // 提示信息 + public int userId; // 用户ID + public string userName; // 用户名 + public string nickName; // 昵称 + public string headImg; // 头像 + public int gender; // 性别,1 表示男,2 表示女 + public string birthday; // 生日 + public int voluteCoin; // 蜗壳 + public int beansCoin; // 蜗牛蛋 + public int ichorCoin; // 灵液 + public int cuteNo; // 靓号 + + // 假设有一个手动查询用户详情的按钮 public Button selectUserInfoButton; + void Awake() + { + // 实现单例模式 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁 + } + else + { + Destroy(gameObject); + } + } + void Start() { // 注册监听事件,当收到 token 时,触发 HandleTokenReceived @@ -262,7 +292,7 @@ public class SelectUserInfo : MonoBehaviour // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - // 假设按钮被点击时调用 OnSelectUserInfoButtonClicked=================================================================== + // 假设按钮被点击时调用 OnSelectUserInfoButtonClicked if (selectUserInfoButton != null) { selectUserInfoButton.onClick.AddListener(OnSelectUserInfoButtonClicked); @@ -289,8 +319,8 @@ public class SelectUserInfo : MonoBehaviour lastSelectUserInfoResponse = await SelectUser(); Debug.Log("HandleGameEscapeIdUpdated 处理的查询用户详情响应: " + lastSelectUserInfoResponse); - // 处理响应内容 - HandleSelectUserResponse(lastSelectUserInfoResponse); + // 解析查询结果 + ParseSelectUserInfoResponse(lastSelectUserInfoResponse); } // 加载初始数据,使用最新的 token @@ -306,8 +336,8 @@ public class SelectUserInfo : MonoBehaviour lastSelectUserInfoResponse = await SelectUser(); Debug.Log("初始加载的查询用户详情响应: " + lastSelectUserInfoResponse); - // 处理响应内容 - HandleSelectUserResponse(lastSelectUserInfoResponse); + // 解析查询结果 + ParseSelectUserInfoResponse(lastSelectUserInfoResponse); } // 按钮点击后触发用户详情查询操作 @@ -324,8 +354,8 @@ public class SelectUserInfo : MonoBehaviour lastSelectUserInfoResponse = await SelectUser(); Debug.Log("用户按钮触发的查询用户详情响应: " + lastSelectUserInfoResponse); - // 处理响应内容 - HandleSelectUserResponse(lastSelectUserInfoResponse); + // 解析查询结果 + ParseSelectUserInfoResponse(lastSelectUserInfoResponse); } // 查询用户详情 @@ -359,50 +389,48 @@ public class SelectUserInfo : MonoBehaviour }; } - // 处理 SelectUser 方法的响应,直接从字符串中获取字段 - private void HandleSelectUserResponse(string response) + // 处理 SelectUser 方法的响应,并解析成全局变量 + private void ParseSelectUserInfoResponse(string response) { + if (string.IsNullOrEmpty(response)) + { + Debug.LogWarning("无法解析用户详情查询响应,响应为空。"); + return; + } + try { - // 使用 JObject 解析 JSON 字符串 - JObject jsonObject = JObject.Parse(response); + // 使用 Newtonsoft.Json 解析响应 + SelectUserInfoResponse userInfoResponse = JsonConvert.DeserializeObject(response); - // 获取 code 和 message - int code = jsonObject.Value("code"); - string message = jsonObject.Value("message"); + // 将解析后的数据赋值给全局变量 + code = userInfoResponse.code; + message = userInfoResponse.message; - if (code == 200) + if (userInfoResponse.data != null) { - JObject data = jsonObject.Value("data"); - if (data != null)//用户信息 - { - int userId = data.Value("userId");//用户ID - string userName = data.Value("userName");//用户名 - string nickName = data.Value("nickName");//呢称 - string headImg = data.Value("headImg");//头像 - int gender = data.Value("gender");//性别 - string birthday = data.Value("birthday");//生日 - int voluteCoin = data.Value("voluteCoin");//蜗壳 - int beansCoin = data.Value("beansCoin");//蜗牛蛋 - int ichorCoin = data.Value("ichorCoin");//灵液 - int cuteNo = data.Value("cuteNo");//靓号 + userId = userInfoResponse.data.userId; + userName = userInfoResponse.data.userName; + nickName = userInfoResponse.data.nickName; + headImg = userInfoResponse.data.headImg; + gender = userInfoResponse.data.gender; + birthday = userInfoResponse.data.birthday; + voluteCoin = userInfoResponse.data.voluteCoin; + beansCoin = userInfoResponse.data.beansCoin; + ichorCoin = userInfoResponse.data.ichorCoin; + cuteNo = userInfoResponse.data.cuteNo; - // 打印输出获取的字段 - Debug.Log($"查询用户信息成功!用户 ID: {userId}, 用户名: {userName}, 昵称: {nickName}, 性别: {(gender == 1 ? "男" : "女")}, 蜗壳: {voluteCoin}, 蜗蛋: {beansCoin}, 灵液: {ichorCoin}, 靓号: {cuteNo}"); - } - else - { - Debug.LogWarning("数据对象为空,无法获取用户详细信息"); - } + Debug.Log($"查询用户信息成功!用户 ID: {userId}, 用户名: {userName}, 昵称: {nickName}, 性别: {(gender == 1 ? "男" : "女")}, " + + $"蜗壳: {voluteCoin}, 蜗蛋: {beansCoin}, 灵液: {ichorCoin}, 靓号: {cuteNo}"); } else { - Debug.LogWarning($"查询用户信息失败,消息: {message}"); + Debug.LogWarning("数据对象为空,无法获取用户详细信息"); } } - catch (Exception ex) + catch (System.Exception e) { - Debug.LogError($"解析响应时出现异常: {ex.Message}"); + Debug.LogWarning("解析用户详情查询响应时出错: " + e.Message); } } @@ -412,10 +440,33 @@ public class SelectUserInfo : MonoBehaviour LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - // 取消按钮的点击监听-============================================================================================== + // 取消按钮的点击监听 if (selectUserInfoButton != null) { selectUserInfoButton.onClick.RemoveListener(OnSelectUserInfoButtonClicked); } } } + +// 用户详情查询响应数据类,用于存储解析后的响应数据 +public class SelectUserInfoResponse +{ + public int code { get; set; } // 返回状态码,例如 200 表示成功 + public string message { get; set; } // 提示信息 + public UserInfo data { get; set; } // 用户信息 +} + +// 用户信息数据类,用于存储用户详细信息 +public class UserInfo +{ + public int userId { get; set; } // 用户ID + public string userName { get; set; } // 用户名 + public string nickName { get; set; } // 昵称 + public string headImg { get; set; } // 头像 + public int gender { get; set; } // 性别,1 表示男,2 表示女 + public string birthday { get; set; } // 生日 + public int voluteCoin { get; set; } // 蜗壳 + public int beansCoin { get; set; } // 蜗牛蛋 + public int ichorCoin { get; set; } // 灵液 + public int cuteNo { get; set; } // 靓号 +} diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/SelectUserInfo14.cs.meta similarity index 100% rename from TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs.meta rename to TheStrongestSnail/Assets/Scripts/Login/11/SelectUserInfo14.cs.meta diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs similarity index 78% rename from TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs rename to TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs index 7860042..b569bb5 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs @@ -7,7 +7,7 @@ using UnityEngine; using System.Threading.Tasks; using Newtonsoft.Json; using UnityEngine.UI; -/*public class UpdateUserInfo : MonoBehaviour +/*public class UpdateUserInfo13 : MonoBehaviour { public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 @@ -111,16 +111,39 @@ using UnityEngine.UI; } }*/ - -public class UpdateUserInfo : MonoBehaviour +//解析+单例 +public class UpdateUserInfo13 : MonoBehaviour { + // 单例模式实现 + public static UpdateUserInfo13 Instance { get; private set; } + + // 全局变量,用于存储服务器返回的具体字段 public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 private string lastUpdateUserInfoResponse = null; // 保存最新的用户信息更新响应 - // 假设有一个手动更新用户信息的按钮========================================================================================= + // 服务器返回的字段,作为全局变量 + public int code; // 状态码,例如 200 表示成功 + public string message; // 提示信息 + public bool data; // 用户信息更新结果,true 表示成功 + + // 假设有一个手动更新用户信息的按钮 public Button updateUserInfoButton; + void Awake() + { + // 实现单例模式 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁 + } + else + { + Destroy(gameObject); + } + } + void Start() { // 注册监听事件,当收到 token 时,触发 HandleTokenReceived @@ -129,7 +152,7 @@ public class UpdateUserInfo : MonoBehaviour // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - // 假设按钮被点击时调用 OnUpdateUserInfoButtonClicked================================================================== + // 假设按钮被点击时调用 OnUpdateUserInfoButtonClicked if (updateUserInfoButton != null) { updateUserInfoButton.onClick.AddListener(OnUpdateUserInfoButtonClicked); @@ -155,6 +178,9 @@ public class UpdateUserInfo : MonoBehaviour // 在接收到 escapeId 更新时自动调用更新用户信息 lastUpdateUserInfoResponse = await UpdateUserInformation(); Debug.Log("HandleGameEscapeIdUpdated 处理的用户信息更新响应: " + lastUpdateUserInfoResponse); + + // 解析查询结果 + ParseUpdateUserInfoResponse(lastUpdateUserInfoResponse); } // 加载初始数据,使用最新的 token @@ -169,6 +195,9 @@ public class UpdateUserInfo : MonoBehaviour // 调用更新用户信息方法 lastUpdateUserInfoResponse = await UpdateUserInformation(); Debug.Log("初始加载的用户信息更新响应: " + lastUpdateUserInfoResponse); + + // 解析查询结果 + ParseUpdateUserInfoResponse(lastUpdateUserInfoResponse); } // 按钮点击后触发用户信息更新操作 @@ -185,6 +214,9 @@ public class UpdateUserInfo : MonoBehaviour lastUpdateUserInfoResponse = await UpdateUserInformation(); Debug.Log("用户按钮触发的用户信息更新响应: " + lastUpdateUserInfoResponse); + // 解析查询结果 + ParseUpdateUserInfoResponse(lastUpdateUserInfoResponse); + // 根据响应做进一步的处理 HandleUpdateUserInfoResponse(lastUpdateUserInfoResponse); } @@ -231,7 +263,7 @@ public class UpdateUserInfo : MonoBehaviour // 处理 UpdateUserInformation 方法的响应 private void HandleUpdateUserInfoResponse(string response) { - if (response.Contains("success")) + if (code == 200 && data) { Debug.Log("更新用户信息成功!"); } @@ -241,16 +273,54 @@ public class UpdateUserInfo : MonoBehaviour } } + // 解析用户信息更新响应,并保存到全局变量 + private void ParseUpdateUserInfoResponse(string response) + { + if (string.IsNullOrEmpty(response)) + { + Debug.LogWarning("无法解析用户信息更新响应,响应为空。"); + return; + } + + try + { + // 使用 Newtonsoft.Json 解析响应 + UpdateUserInfoResponse updateResponse = JsonConvert.DeserializeObject(response); + + // 将解析后的数据赋值给全局变量 + code = updateResponse.code; + message = updateResponse.message; + data = updateResponse.data; + + Debug.Log("解析后的用户信息更新结果: " + + "\n状态码: " + code + + "\n提示信息: " + message + + "\n更新成功: " + data); + } + catch (System.Exception e) + { + Debug.LogWarning("解析用户信息更新响应时出错: " + e.Message); + } + } + void OnDestroy() { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - // 取消按钮的点击监听=============================================================================================== + // 取消按钮的点击监听 if (updateUserInfoButton != null) { updateUserInfoButton.onClick.RemoveListener(OnUpdateUserInfoButtonClicked); } } } + +// 用户信息更新响应数据类,用于存储解析后的响应数据 +public class UpdateUserInfoResponse +{ + public int code { get; set; } // 返回状态码,例如 200 表示成功 + public string message { get; set; } // 提示信息 + public bool data { get; set; } // 用户信息更新结果,true 表示成功 +} diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs.meta similarity index 83% rename from TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs.meta rename to TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs.meta index 5947d4f..6b51681 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs.meta +++ b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo13.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3cdc7291c1f2c68489b960c1d53cbac6 +guid: 3e317c8c24b13004bb49858be0928128 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs b/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult515.cs similarity index 73% rename from TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs rename to TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult515.cs index b01a715..cf9ffbb 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult515.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using UnityEngine; using System.Threading.Tasks; using Newtonsoft.Json; -using UnityEngine.UI; -/*public class UserBetResult : MonoBehaviour +using UnityEngine.UI; +/*public class UserBetResult515 : MonoBehaviour { public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 @@ -107,16 +107,38 @@ using UnityEngine.UI; }*/ +//解析+单例 - -public class UserBetResult : MonoBehaviour +public class UserBetResult515 : MonoBehaviour { + // 单例模式实现 + public static UserBetResult515 Instance { get; private set; } + + // 全局变量,用于存储服务器返回的具体字段 public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + public int userId; private string lastUserBetResultResponse = null; // 保存最新的用户下注结果响应 - // 假设有一个按钮可以手动查询用户下注结果============================================================================= - //public Button queryUserBetButton; + // 服务器返回的字段,作为全局变量 + public int code; // 状态码,例如 200 表示成功 + public string message; // 提示信息 + public int roomNoKill; // 被击杀的房间号 + public int roomNoRemain; // 留存的房间号 + + void Awake() + { + // 实现单例模式 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁 + } + else + { + Destroy(gameObject); + } + } void Start() { @@ -125,12 +147,6 @@ public class UserBetResult : MonoBehaviour // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - - //// 假设按钮被点击时调用 OnQueryUserBetButtonClicked===================================================================== - //if (queryUserBetButton != null) - //{ - // queryUserBetButton.onClick.AddListener(OnQueryUserBetButtonClicked); - //} } // 当接收到 token 时触发此方法,仅保存 token @@ -152,6 +168,9 @@ public class UserBetResult : MonoBehaviour // 调用查询用户下注结果方法 lastUserBetResultResponse = await QueryUserBetResult(); Debug.Log("HandleGameEscapeIdUpdated 处理的查询结果响应: " + lastUserBetResultResponse); + + // 解析查询结果 + ParseUserBetResultResponse(lastUserBetResultResponse); } // 加载初始数据,使用最新的 token @@ -166,30 +185,9 @@ public class UserBetResult : MonoBehaviour // 调用查询用户下注结果方法 lastUserBetResultResponse = await QueryUserBetResult(); Debug.Log("初始加载的查询用户下注结果响应: " + lastUserBetResultResponse); - } - // 按钮点击后触发用户下注结果查询操作 - public async void OnQueryUserBetButtonClicked() - { - // 检查 token 和 escapeId 是否已正确设置 - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法查询下注结果,token 未设置。"); - return; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法查询下注结果,escapeId 未设置。"); - return; - } - - // 调用查询用户下注结果方法 - lastUserBetResultResponse = await QueryUserBetResult(); - Debug.Log("用户按钮触发的查询结果响应: " + lastUserBetResultResponse); - - // 根据响应做进一步的处理 - HandleUserBetResultResponse(lastUserBetResultResponse); + // 解析查询结果 + ParseUserBetResultResponse(lastUserBetResultResponse); } // 查询用户下注结果 @@ -210,11 +208,11 @@ public class UserBetResult : MonoBehaviour var headers = CreateHeaders(); string body = $@" {{ - ""userId"": 106, + ""userId"": {userId}, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); return response; // 返回响应 } @@ -237,7 +235,7 @@ public class UserBetResult : MonoBehaviour // 处理 QueryUserBetResult 方法的响应 private void HandleUserBetResultResponse(string response) { - if (response.Contains("success")) + if (response.Contains("\"code\":200")) { Debug.Log("查询下注结果成功!"); } @@ -247,16 +245,62 @@ public class UserBetResult : MonoBehaviour } } + // 解析用户下注结果响应,并保存到全局变量 + private void ParseUserBetResultResponse(string response) + { + if (string.IsNullOrEmpty(response)) + { + Debug.LogWarning("无法解析下注结果,响应为空。"); + return; + } + + try + { + // 使用 Newtonsoft.Json 解析响应 + BetResultResponse betResult = JsonConvert.DeserializeObject(response); + + // 将解析后的数据赋值给全局变量 + code = betResult.code; + message = betResult.message; + + if (betResult.data != null) + { + roomNoKill = betResult.data.roomNoKill; + roomNoRemain = betResult.data.roomNoRemain; + } + + Debug.Log("解析后的下注结果: " + + "\n状态码: " + code + + "\n提示信息: " + message + + "\n被击杀的房间: " + roomNoKill + + "\n留存的房间: " + roomNoRemain); + } + catch (System.Exception e) + { + Debug.LogWarning("解析下注结果时出错: " + e.Message); + } + } + void OnDestroy() { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - - //// 取消按钮的点击监听================================================================================================ - //if (queryUserBetButton != null) - //{ - // queryUserBetButton.onClick.RemoveListener(OnQueryUserBetButtonClicked); - //} } } + +// 下注结果响应数据类,用于存储解析后的响应数据 +public class BetResultResponse +{ + public int code { get; set; } // 返回状态码,例如 200 表示成功 + public string message { get; set; } // 提示信息 + public BetResultData data { get; set; } // 具体的下注数据 +} + +// 下注结果数据类,用于存储大逃亡详情 +public class BetResultData +{ + public int roomNoKill { get; set; } // 被击杀的房间号 + public int roomNoRemain { get; set; } // 留存的房间号 +} + diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult515.cs.meta similarity index 100% rename from TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs.meta rename to TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult515.cs.meta diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs b/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs index e29d12a..ef91334 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs @@ -143,10 +143,7 @@ using UnityEngine.UI; } }*/ - - - -public class LoadMall : MonoBehaviour +/*public class LoadMall : MonoBehaviour { public string token = null; // 保存最新的 token,初始为 null public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 @@ -324,4 +321,231 @@ public class LoadMall : MonoBehaviour loadMallButton.onClick.RemoveListener(OnLoadMallButtonClicked); } } +}*/ + +//解析+单例 + +public class LoadMall : MonoBehaviour +{ + // 单例模式实现 + public static LoadMall Instance { get; private set; } + + // 全局变量,用于存储服务器返回的具体字段 + public string token = null; // 保存最新的 token,初始为 null + public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + private string lastMallResponse = null; // 保存最新的商城操作响应 + + // 服务器返回的字段,作为全局变量 + public int code; // 返回状态码,例如 200 表示成功 + public string message; // 提示信息 + public int pageNo; // 商品分页信息中的起始页 + public int pageSize; // 商品分页信息中的每页展示 + public int totalCount; // 商品分页信息中的总记录数 + public List productList; // 商品数据列表 + + // 假设有一个手动加载商城数据的按钮 + public Button loadMallButton; + + void Awake() + { + // 实现单例模式 + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁 + } + else + { + Destroy(gameObject); + } + } + + void Start() + { + // 注册监听事件,当收到 token 时,触发 HandleTokenReceived + LoginAndGetToken.OnTokenReceived += HandleTokenReceived; + + // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + + // 假设按钮被点击时调用 OnLoadMallButtonClicked + if (loadMallButton != null) + { + loadMallButton.onClick.AddListener(OnLoadMallButtonClicked); + } + } + + // 当接收到 token 时触发此方法,仅保存 token + public void HandleTokenReceived(string receivedToken) + { + token = receivedToken; // 保存最新的 token + Debug.Log("接收到新的 token: " + token); + + // 首次调用加载初始数据 + LoadInitialData(); + } + + // 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId + public async void HandleGameEscapeIdUpdated(int newGameEscapeId) + { + escapeId = newGameEscapeId; // 保存最新的 escapeId + Debug.Log("接收到新的 GameEscapeId: " + escapeId); + + // 在接收到 escapeId 更新时自动调用加载商城数据 + lastMallResponse = await LoadMallData(); + Debug.Log("HandleGameEscapeIdUpdated 处理的商城数据响应: " + lastMallResponse); + + // 解析商城数据响应 + ParseMallResponse(lastMallResponse); + } + + // 加载初始数据,使用最新的 token + public async void LoadInitialData() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("无法加载初始数据,token 未设置。"); + return; + } + + // 调用加载商城数据方法 + lastMallResponse = await LoadMallData(); + Debug.Log("初始加载的商城数据响应: " + lastMallResponse); + + // 解析商城数据响应 + ParseMallResponse(lastMallResponse); + } + + // 按钮点击后触发商城数据加载操作 + public async void OnLoadMallButtonClicked() + { + // 检查 token 是否已正确设置 + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("无法加载商城数据,token 未设置。"); + return; + } + + // 调用加载商城数据方法 + lastMallResponse = await LoadMallData(); + Debug.Log("用户按钮触发的商城数据加载响应: " + lastMallResponse); + + // 解析商城数据响应 + ParseMallResponse(lastMallResponse); + } + + // 加载商城数据 + public async Task LoadMallData() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("无法加载商城数据,token 未设置。"); + return null; + } + + var headers = CreateHeaders(); + string body = @"{}"; // 这里可以根据需要修改请求参数 + + Debug.Log("正在加载商城数据..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", body, headers); + Debug.Log("商城数据响应: " + response); + return response; // 返回响应 + } + + // 创建请求头,使用最新的 token + public Dictionary CreateHeaders() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + + return new Dictionary + { + { "Authorization", token } + }; + } + + // 解析商城数据响应,并保存到全局变量 + private void ParseMallResponse(string response) + { + if (string.IsNullOrEmpty(response)) + { + Debug.LogWarning("无法解析商城数据响应,响应为空。"); + return; + } + + try + { + // 使用 Newtonsoft.Json 解析响应 + MallResponse mallResponse = JsonConvert.DeserializeObject(response); + + // 将解析后的数据赋值给全局变量 + code = mallResponse.code; + message = mallResponse.message; + + if (mallResponse.data != null) + { + pageNo = mallResponse.data.pageNo; + pageSize = mallResponse.data.pageSize; + totalCount = mallResponse.data.totalCount; + productList = mallResponse.data.dataList; + + // 打印商品列表信息 + foreach (var product in productList) + { + Debug.Log($"商品 ID: {product.productId}, 名称: {product.name}, 价格: {product.price}"); + } + } + else + { + Debug.LogWarning("商城数据对象为空,无法获取详细信息"); + } + } + catch (System.Exception e) + { + Debug.LogWarning("解析商城数据响应时出错: " + e.Message); + } + } + + void OnDestroy() + { + // 注销监听事件,避免内存泄漏 + LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + + // 取消按钮的点击监听 + if (loadMallButton != null) + { + loadMallButton.onClick.RemoveListener(OnLoadMallButtonClicked); + } + } +} + +// 商城数据响应类,用于存储解析后的响应数据 +public class MallResponse +{ + public int code { get; set; } // 返回状态码,例如 200 表示成功 + public string message { get; set; } // 提示信息 + public MallData data { get; set; } // 商城分页信息 +} + +// 商城分页数据类,用于存储分页详细信息 +public class MallData +{ + public int pageNo { get; set; } // 起始页 + public int pageSize { get; set; } // 每页展示 + public int totalCount { get; set; } // 总记录数 + public List dataList { get; set; } // 商品数据列表 +} + +// 商品类,用于存储商品的详细信息 +public class Product +{ + public int productId { get; set; } // 商品ID + public string name { get; set; } // 商品名称 + public string cover { get; set; } // 商品封面 + public string pic { get; set; } // 商品图片 + public float price { get; set; } // 商品价格 } diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/motherFucker511.cs b/TheStrongestSnail/Assets/Scripts/Login/11/motherFucker511.cs index f1cd2a2..06a4a5e 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/motherFucker511.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/motherFucker511.cs @@ -43,7 +43,7 @@ public class motherFucker511 : MonoBehaviour }; // 发送请求并接收响应 - string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51); + string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); Debug.Log("5.1查询最近一场大屠杀" + response51); } diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/queryRecord516.cs b/TheStrongestSnail/Assets/Scripts/Login/11/queryRecord516.cs index 7cd06bb..075870e 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/queryRecord516.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/queryRecord516.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class query10Recird : MonoBehaviour +public class queryRecord516 : MonoBehaviour { // Start is called before the first frame update void Start() diff --git a/TheStrongestSnail/Assets/Scripts/Login/selectLatest511.cs b/TheStrongestSnail/Assets/Scripts/Login/selectLatest511.cs index 9f100da..6c9e332 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/selectLatest511.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/selectLatest511.cs @@ -138,28 +138,45 @@ public class selectLatest511 : MonoBehaviour { public int gameEscapeId; public int carrySeconds; + public string gameNo; // 游戏编号 + public int demonMode; + public string startTime; + public string betTime; + public string countTime; + public string settleTime; + public int status; + public string roomNoKill; + public string roomNoRemain; + public float beansCoinAll; + public float beansCoinKill; + public float beansCoinRemain; + public float beansCoinFee; + public float beansCoinRank; + public float beansCoinDivide; + + + public int escapeId; // 逃脱游戏的ID + public int roomNo; // 房间号 + public float roomBeansCoin; // 房间中豆币数量 - // 定义一个事件,当 gameEscapeId 被更新时触发 public static event Action OnGameEscapeIdUpdated; - private string token; // 用于保存收到的 token + private string token; void Start() { - // 监听登录获取 token LoginAndGetToken.OnTokenReceived += HandleTokenReceived; selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } - void HandleTokenReceived(string token) + async void HandleTokenReceived(string token) { this.token = token; Debug.Log("HandleTokenReceived监听:" + token); - // 一开始获取 token 时立即运行一次 LatestGame511 - LatestGame511(token).Wait(); + // 异步调用,避免阻塞主线程 + await LatestGame511(token); - // 然后启动协程,每30秒调用一次 LatestGame511 StartCoroutine(GameEscapeRoutine(token)); } @@ -172,67 +189,81 @@ public class selectLatest511 : MonoBehaviour { while (true) { - yield return new WaitForSeconds(30f); // 每30秒暂停一次 - yield return LatestGame511(token); // 调用 LatestGame511 方法 + yield return new WaitForSeconds(1f);//============================================================================================= + yield return LatestGame511(token); } } public async Task LatestGame511(string token) { - // 用来给请求头赋值 - string Authorization = token; - - // 设置请求头 - Dictionary head511 = new Dictionary + try { - { "Authorization", Authorization } - }; - - // 发送请求并接收响应 - string response511 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head511); - Debug.Log("5.1.1查询最近一场大屠杀" + response511); - - // 解析JSON数据为 Response 对象 - Response response = JsonConvert.DeserializeObject(response511); - - if (response != null && response.code == 200 && response.data != null) - { - // 保存解析后的字段 - gameEscapeId = response.data.gameEscapeModel.id; - carrySeconds = response.data.carrySeconds; - - // 使用其他字段 - string gameNo = response.data.gameEscapeModel.gameNo; - float beansCoinAll = response.data.gameEscapeModel.beansCoinAll; - - Debug.Log($"Game Escape ID: {gameEscapeId}"); - Debug.Log($"Carry Seconds: {carrySeconds}"); - Debug.Log($"Game No: {gameNo}"); - Debug.Log($"Beans Coin All: {beansCoinAll}"); - - // 如果你想要处理房间列表 - foreach (var room in response.data.gameEscapeRoomResponseVoList) + string Authorization = token; + Dictionary head511 = new Dictionary { - int roomNo = room.roomNo; - float roomBeansCoin = room.roomBeansCoin; - Debug.Log($"Room No: {roomNo}, Room Beans Coin: {roomBeansCoin}"); - } + { "Authorization", Authorization } + }; - // 触发事件,通知所有订阅者 - OnGameEscapeIdUpdated?.Invoke(gameEscapeId); + string response511 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head511); + Debug.Log("5.1.1查询最近一场大屠杀" + response511); + + Response response = JsonConvert.DeserializeObject(response511); + + if (response != null && response.code == 200 && response.data != null) + { + gameEscapeId = response.data.gameEscapeModel.id; + carrySeconds = response.data.carrySeconds; + gameNo = response.data.gameEscapeModel.gameNo; + demonMode = response.data.gameEscapeModel.demonMode; + startTime = response.data.gameEscapeModel.startTime; + betTime = response.data.gameEscapeModel.betTime; + countTime = response.data.gameEscapeModel.countTime; + settleTime = response.data.gameEscapeModel.settleTime; + status = response.data.gameEscapeModel.status; + roomNoKill = response.data.gameEscapeModel.roomNoKill; + roomNoRemain = response.data.gameEscapeModel.roomNoRemain; + beansCoinAll = response.data.gameEscapeModel.beansCoinAll; + beansCoinKill = response.data.gameEscapeModel.beansCoinKill; + beansCoinRemain = response.data.gameEscapeModel.beansCoinRemain; + beansCoinFee = response.data.gameEscapeModel.beansCoinFee; + beansCoinRank = response.data.gameEscapeModel.beansCoinRank; + beansCoinDivide = response.data.gameEscapeModel.beansCoinDivide; + + + + + HegemonTime.instance.HadInfAndStartGame(); + + Debug.Log($"Game Escape ID: {gameEscapeId}"); + Debug.Log($"Carry Seconds: {carrySeconds}"); + Debug.Log($"Game No: {response.data.gameEscapeModel.gameNo}"); + Debug.Log($"Beans Coin All: {response.data.gameEscapeModel.beansCoinAll}"); + + foreach (var room in response.data.gameEscapeRoomResponseVoList) + { + Debug.Log($"Room No: {room.roomNo}, Room Beans Coin: {room.roomBeansCoin}"); + } + + OnGameEscapeIdUpdated?.Invoke(gameEscapeId); + } + else + { + Debug.LogError("解析失败或响应错误"); + } } - else + catch (Exception ex) { - Debug.LogError("解析失败或响应错误"); + Debug.LogError("发生异常:" + ex.Message); } } void OnDestroy() { - // 取消监听,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } + // 数据类 [Serializable] public class GameEscapeModel @@ -279,7 +310,7 @@ public class selectLatest511 : MonoBehaviour public string message; // 返回信息 public Data data; // 数据对象 } + + } - -