diff --git a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity index 4f01436..5929156 100644 --- a/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity +++ b/TheStrongestSnail/Assets/Scenes/Battle_Royale.unity @@ -10439,8 +10439,8 @@ GameObject: - component: {fileID: 2127674356} - component: {fileID: 2127674357} - component: {fileID: 2127674358} - - component: {fileID: 2127674359} - component: {fileID: 2127674360} + - component: {fileID: 2127674361} m_Layer: 5 m_Name: InfoObject m_TagString: Untagged @@ -10495,20 +10495,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &2127674359 -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: b7936430f01cc8343a1e62fc2052a12b, type: 3} - m_Name: - m_EditorClassIdentifier: - gameEscapeId: 0 - carrySeconds: 0 --- !u!114 &2127674360 MonoBehaviour: m_ObjectHideFlags: 0 @@ -10523,6 +10509,20 @@ MonoBehaviour: m_EditorClassIdentifier: token: escapeId: -1 +--- !u!114 &2127674361 +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: e861ed692e9579d44968fc5f4e3a7b37, type: 3} + m_Name: + m_EditorClassIdentifier: + gameEscapeId: 0 + carrySeconds: 0 --- !u!1 &2135586305 GameObject: m_ObjectHideFlags: 0 diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs index 5df69eb..52260c8 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/HegemonTime.cs @@ -22,7 +22,7 @@ public class HegemonTime : MonoBehaviour private void Update() { - Debug.Log("carrySeconds:" + InfoObject.GetComponent().carrySeconds); + // Debug.Log("carrySeconds:" + InfoObject.GetComponent().carrySeconds); } public IEnumerator StartGame() diff --git a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs b/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs index e2c888f..cb76057 100644 --- a/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs +++ b/TheStrongestSnail/Assets/Scripts/Battle_Royale/Test.cs @@ -56,7 +56,7 @@ public class Test : MonoBehaviour { "Authorization", Authorization }, // 设置授权头 }; - string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); + string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51); Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); // 查询最近一场大逃亡游戏详情: // 解析JSON数据 diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs b/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs deleted file mode 100644 index eb319b0..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs +++ /dev/null @@ -1,262 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.Threading.Tasks; -using Newtonsoft.Json; -using UnityEngine.UI; -/*public class QueryEscapeRoom : MonoBehaviour -{ - public string token = null; // 保存最新的 token,初始为 null - public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 - - void Start() - { - // 注册监听事件,当收到 token 时,触发 HandleTokenReceived - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - - // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - } - - // 当接收到 token 时触发此方法,仅保存 token - public void HandleTokenReceived(string receivedToken) - { - token = receivedToken; // 保存最新的 token - // 首次调用加载初始数据 - LoadInitialData(); - //LoadGameEscapeData(); - //Debug.Log("接收到新的 token: " + token); - } - - // 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId - public async void HandleGameEscapeIdUpdated(int newGameEscapeId) - { - escapeId = newGameEscapeId; // 保存最新的 escapeId - await QueryEscapeRoomDetails();//=====================================================================放在这里仅因为懒得写触发条件,可以放在任何地方,比如input.GetKeyDown.....必须改掉,吃服务器 - //Debug.Log("接收到新的 GameEscapeId: " + escapeId); - } - - - // 加载初始数据,使用最新的 token - public async void LoadInitialData() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载初始数据,token 未设置。"); - return; - } - await QueryEscapeRoomDetails();//=====================================================================放在此处只为解除一个黄色报错,看着闹心。但可以不要 - } - - // 加载游戏逃亡数据,使用最新的 escapeId 和 token - public async void selectQueryKill1() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载游戏逃亡数据,token 未设置。"); - return; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法加载游戏逃亡数据,escapeId 未设置。"); - return; - } - - await QueryEscapeRoomDetails();//========================================================================================================================================================================== - - } - - //=============================================================================================================================================================================================================================== - // 查询逃亡房间详情 - public async Task QueryEscapeRoomDetails() - { - var headers = CreateHeaders(); - string body = $@" - {{ - ""userId"": 106, - ""escapeId"": {escapeId} - }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); - Debug.Log("逃亡房间详情响应: " + response); - } - //=============================================================================================================================================================================================================================== - - // 创建请求头,使用最新的 token - public Dictionary CreateHeaders() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("尝试创建请求头时,token 未设置。"); - return new Dictionary(); - } - - return new Dictionary - { - { "Authorization", token } - }; - } - - void OnDestroy() - { - // 注销监听事件,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - } -}*/ - - - -public class QueryEscapeRoom : MonoBehaviour -{ - public string token = null; // 保存最新的 token,初始为 null - public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 - private string lastEscapeRoomResponse = null; // 保存最新的逃亡房间查询响应 - - // 假设有一个手动查询逃亡房间详情的按钮=================================================================================== - public Button queryEscapeRoomButton; - - void Start() - { - // 注册监听事件,当收到 token 时,触发 HandleTokenReceived - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - - // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - - // 假设按钮被点击时调用 OnQueryEscapeRoomButtonClicked================================================================ - if (queryEscapeRoomButton != null) - { - queryEscapeRoomButton.onClick.AddListener(OnQueryEscapeRoomButtonClicked); - } - } - - // 当接收到 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 更新时自动调用查询逃亡房间详情 - lastEscapeRoomResponse = await QueryEscapeRoomDetails(); - Debug.Log("HandleGameEscapeIdUpdated 处理的查询逃亡房间响应: " + lastEscapeRoomResponse); - } - - // 加载初始数据,使用最新的 token - public async void LoadInitialData() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载初始数据,token 未设置。"); - return; - } - - // 调用查询逃亡房间详情方法 - lastEscapeRoomResponse = await QueryEscapeRoomDetails(); - Debug.Log("初始加载的查询逃亡房间详情响应: " + lastEscapeRoomResponse); - } - - // 按钮点击后触发逃亡房间详情查询操作 - public async void OnQueryEscapeRoomButtonClicked() - { - // 检查 token 和 escapeId 是否已正确设置 - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法查询逃亡房间详情,token 未设置。"); - return; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法查询逃亡房间详情,escapeId 未设置。"); - return; - } - - // 调用查询逃亡房间详情方法 - lastEscapeRoomResponse = await QueryEscapeRoomDetails(); - Debug.Log("用户按钮触发的查询逃亡房间详情响应: " + lastEscapeRoomResponse); - - // 根据响应做进一步的处理 - HandleEscapeRoomResponse(lastEscapeRoomResponse); - } - - // 查询逃亡房间详情 - public async Task QueryEscapeRoomDetails() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法查询逃亡房间详情,token 未设置。"); - return null; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法查询逃亡房间详情,escapeId 未设置。"); - return null; - } - - var headers = CreateHeaders(); - string body = $@" - {{ - ""userId"": 106, - ""escapeId"": {escapeId} - }}"; - - Debug.Log("正在查询逃亡房间详情..."); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "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 } - }; - } - - // 处理 QueryEscapeRoomDetails 方法的响应 - private void HandleEscapeRoomResponse(string response) - { - if (response.Contains("success")) - { - Debug.Log("查询逃亡房间详情成功!"); - } - else - { - Debug.LogWarning("查询逃亡房间详情失败,服务器响应: " + response); - } - } - - void OnDestroy() - { - // 注销监听事件,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - - // 取消按钮的点击监听================================================================================================ - if (queryEscapeRoomButton != null) - { - queryEscapeRoomButton.onClick.RemoveListener(OnQueryEscapeRoomButtonClicked); - } - } -} diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs.meta deleted file mode 100644 index 69aa20a..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/11/QueryEscapeRoom.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b27d2d49f51751e42b31653d0b0b8d2d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs index f04a210..7860042 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/UpdateUserInfo.cs @@ -18,7 +18,7 @@ using UnityEngine.UI; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -107,7 +107,7 @@ using UnityEngine.UI; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ @@ -127,7 +127,7 @@ public class UpdateUserInfo : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; // 假设按钮被点击时调用 OnUpdateUserInfoButtonClicked================================================================== if (updateUserInfoButton != null) @@ -245,7 +245,7 @@ public class UpdateUserInfo : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; // 取消按钮的点击监听=============================================================================================== if (updateUserInfoButton != null) diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs b/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs index 85e789e..b01a715 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/UserBetResult.cs @@ -16,7 +16,7 @@ using UnityEngine.UI; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -78,7 +78,7 @@ using UnityEngine.UI; ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); } //=============================================================================================================================================================================================================================== @@ -102,7 +102,7 @@ using UnityEngine.UI; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ @@ -124,7 +124,7 @@ public class UserBetResult : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; //// 假设按钮被点击时调用 OnQueryUserBetButtonClicked===================================================================== //if (queryUserBetButton != null) @@ -214,7 +214,7 @@ public class UserBetResult : MonoBehaviour ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); return response; // 返回响应 } @@ -251,7 +251,7 @@ public class UserBetResult : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; //// 取消按钮的点击监听================================================================================================ //if (queryUserBetButton != null) diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs b/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs index accae73..74f13bf 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/gamber.cs @@ -16,7 +16,7 @@ using UnityEngine.UI; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -80,7 +80,7 @@ using UnityEngine.UI; ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); } //=============================================================================================================================================================================================================================== @@ -104,7 +104,7 @@ using UnityEngine.UI; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ @@ -124,7 +124,7 @@ public class Gamber : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; // 假设下注按钮被点击时调用 OnUserBetButtonClicked=================================================================== if (userBetButton != null) @@ -201,7 +201,7 @@ public class Gamber : MonoBehaviour ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); return response; // 返回响应 } @@ -238,7 +238,7 @@ public class Gamber : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; // 取消按钮的点击监听================================================================================================ if (userBetButton != null) diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs b/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs index 0c7e20f..e29d12a 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/loadMall.cs @@ -16,7 +16,7 @@ using UnityEngine.UI; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -139,7 +139,7 @@ using UnityEngine.UI; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ @@ -161,7 +161,7 @@ public class LoadMall : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; // 假设按钮被点击时调用 OnLoadMallButtonClicked======================================================================== if (loadMallButton != null) @@ -316,7 +316,7 @@ public class LoadMall : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; // 取消按钮的点击监听============================================================================================== if (loadMallButton != null) diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs b/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs deleted file mode 100644 index 475e35e..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs +++ /dev/null @@ -1,265 +0,0 @@ - - -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using System.Threading.Tasks; -using Newtonsoft.Json; -using UnityEngine.UI; -/*public class selectQueryKill : MonoBehaviour -{ - public string token = null; // 保存最新的 token,初始为 null - public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 - - - void Start() - { - // 注册监听事件,当收到 token 时,触发 HandleTokenReceived - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - - // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - } - - // 当接收到 token 时触发此方法,仅保存 token - public void HandleTokenReceived(string receivedToken) - { - token = receivedToken; // 保存最新的 token - // 首次调用加载初始数据 - LoadInitialData(); - //LoadGameEscapeData(); - //Debug.Log("接收到新的 token: " + token); - } - - // 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId - public async void HandleGameEscapeIdUpdated(int newGameEscapeId) - { - escapeId = newGameEscapeId; // 保存最新的 escapeId - await QueryKill();//==================================================================================放在这里仅因为懒得写触发条件,可以放在任何地方,比如input.GetKeyDown.....必须改 - // Debug.Log("接收到新的 GameEscapeId: " + escapeId); - } - - - // 加载初始数据,使用最新的 token - public async void LoadInitialData() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载初始数据,token 未设置。"); - return; - } - await QueryKill(); - } - - // 加载游戏逃亡数据,使用最新的 escapeId 和 token - public async void selectQueryKill1() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载游戏逃亡数据,token 未设置。"); - return; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法加载游戏逃亡数据,escapeId 未设置。"); - return; - } - // 查询击杀数据 - await QueryKill();//================================================================================================================================= - - } - -//=============================================================================================================================================================================================================================== - // 查询击杀信息 - public async Task QueryKill() - { - var headers = CreateHeaders(); - string body = $@" - {{ - ""userId"": 106, - ""escapeId"": {escapeId} - }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); - Debug.Log("查询击杀信息响应: " + response); - } -//=============================================================================================================================================================================================================================== - - // 创建请求头,使用最新的 token - public Dictionary CreateHeaders() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("尝试创建请求头时,token 未设置。"); - return new Dictionary(); - } - - return new Dictionary - { - { "Authorization", token } - }; - } - - void OnDestroy() - { - // 注销监听事件,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - } -}*/ - - - -public class SelectQueryKill : MonoBehaviour -{ - public string token = null; // 保存最新的 token,初始为 null - public int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 - private string lastQueryKillResponse = null; // 保存最新的击杀信息查询响应 - - // 假设有一个手动查询击杀信息的按钮======================================================================================= - public Button queryKillButton; - - void Start() - { - // 注册监听事件,当收到 token 时,触发 HandleTokenReceived - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - - // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - - // 假设按钮被点击时调用 OnQueryKillButtonClicked====================================================================== - if (queryKillButton != null) - { - queryKillButton.onClick.AddListener(OnQueryKillButtonClicked); - } - } - - // 当接收到 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 更新时自动调用查询击杀信息 - lastQueryKillResponse = await QueryKill(); - Debug.Log("HandleGameEscapeIdUpdated 处理的查询击杀信息响应: " + lastQueryKillResponse); - } - - // 加载初始数据,使用最新的 token - public async void LoadInitialData() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法加载初始数据,token 未设置。"); - return; - } - - // 调用查询击杀信息方法 - lastQueryKillResponse = await QueryKill(); - Debug.Log("初始加载的查询击杀信息响应: " + lastQueryKillResponse); - } - - // 按钮点击后触发击杀信息查询操作 - public async void OnQueryKillButtonClicked() - { - // 检查 token 和 escapeId 是否已正确设置 - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法查询击杀信息,token 未设置。"); - return; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法查询击杀信息,escapeId 未设置。"); - return; - } - - // 调用查询击杀信息方法 - lastQueryKillResponse = await QueryKill(); - Debug.Log("用户按钮触发的查询击杀信息响应: " + lastQueryKillResponse); - - // 根据响应做进一步的处理 - HandleQueryKillResponse(lastQueryKillResponse); - } - - // 查询击杀信息 - public async Task QueryKill() - { - if (string.IsNullOrEmpty(token)) - { - Debug.LogWarning("无法查询击杀信息,token 未设置。"); - return null; - } - - if (escapeId == -1) - { - Debug.LogWarning("无法查询击杀信息,escapeId 未设置。"); - return null; - } - - var headers = CreateHeaders(); - string body = $@" - {{ - ""userId"": 106, - ""escapeId"": {escapeId} - }}"; - - Debug.Log("正在查询击杀信息..."); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "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 } - }; - } - - // 处理 QueryKill 方法的响应 - private void HandleQueryKillResponse(string response) - { - if (response.Contains("success")) - { - Debug.Log("查询击杀信息成功!"); - } - else - { - Debug.LogWarning("查询击杀信息失败,服务器响应: " + response); - } - } - - void OnDestroy() - { - // 注销监听事件,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; - - // 取消按钮的点击监听================================================================================================= - if (queryKillButton != null) - { - queryKillButton.onClick.RemoveListener(OnQueryKillButtonClicked); - } - } -} diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs.meta deleted file mode 100644 index a376f4f..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/11/selectQueryKill.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c230883956c0b3546a885c300ad34498 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs b/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs index c3d205c..0065e3d 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs @@ -17,7 +17,7 @@ using Newtonsoft.Json.Linq; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -101,7 +101,7 @@ using Newtonsoft.Json.Linq; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ @@ -123,7 +123,7 @@ using Newtonsoft.Json.Linq; LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; // 假设按钮被点击时调用 OnSelectUserInfoButtonClicked if (selectUserInfoButton != null) @@ -233,7 +233,7 @@ using Newtonsoft.Json.Linq; { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; // 取消按钮的点击监听 if (selectUserInfoButton != null) @@ -260,7 +260,7 @@ public class SelectUserInfo : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; // 假设按钮被点击时调用 OnSelectUserInfoButtonClicked=================================================================== if (selectUserInfoButton != null) @@ -410,7 +410,7 @@ public class SelectUserInfo : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; // 取消按钮的点击监听-============================================================================================== if (selectUserInfoButton != null) diff --git a/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs b/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs index 441b4a1..a85af08 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs @@ -28,6 +28,7 @@ public class LoginAndGetToken : MonoBehaviour string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body)); //Debug.Log("LoginAndGetToken登录:"+loginResponse); string token = getToken(loginResponse); + int userId = getUserId(loginResponse); OnTokenReceived?.Invoke(token); //登录请求//已通过 } @@ -51,6 +52,36 @@ public class LoginAndGetToken : MonoBehaviour return null; } } + //获取userId + public static int getUserId(string json) + { + try + { + // 解析 JSON 字符串为 JObject + JObject parsedJson = JObject.Parse(json); + + // 从 JObject 中提取 userId 字段的值 + string userIdString = parsedJson["data"]?["userId"]?.ToString(); + + // 尝试将 userId 转换为 int + if (int.TryParse(userIdString, out int userId)) + { + return userId; // 返回解析后的 userId + } + else + { + Console.WriteLine("Failed to parse userId as an integer."); + return -1; // 返回 -1 表示解析失败 + } + } + catch (Exception ex) + { + // 处理解析过程中可能出现的异常 + Console.WriteLine("An error occurred while parsing the JSON: " + ex.Message); + return -1; // 返回 -1 表示解析失败 + } + } + [Serializable] public class loginbody//登录和注册用 { diff --git a/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs b/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs index eada41c..6ac9360 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs @@ -19,7 +19,7 @@ public class WebConnact : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } void HandleTokenReceived(string receivedToken) @@ -167,7 +167,7 @@ public class WebConnact : MonoBehaviour { "Authorization", Authorization }, // 设置授权头 }; // 使用最新的 escapeId 在请求体中 - string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); + string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51); Debug.Log("5.1查询最近一场大屠杀: " + response51); //// ==================================================================================================================== @@ -185,7 +185,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response512 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", queryEscapeRoomListBody, head512); + string response512 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", queryEscapeRoomListBody, head512); Debug.Log("5.1.2查询各大逃亡房间最新详情(高性能版): " + response512); @@ -201,7 +201,7 @@ public class WebConnact : MonoBehaviour ""bet"": 100, ""roomNo"":1 }}"; - string response513 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", userBetBody, head513); + string response513 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", userBetBody, head513); Debug.Log("5.1.3,用户下注:" + response513); //5.1.4,查询击杀 @@ -214,7 +214,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", selectKill, head514); + string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", selectKill, head514); Debug.Log("5.1.4,查询击杀:" + response514); ////5.1.5,查询结算 @@ -227,7 +227,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response515 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", queryUserBetResult, head515); + string response515 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", queryUserBetResult, head515); Debug.Log("5.1.5,查询结算:" + response515); } @@ -235,7 +235,7 @@ public class WebConnact : MonoBehaviour { // 取消监听,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } // Update is called once per frame @@ -322,7 +322,7 @@ public class WebConnact : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法 @@ -446,7 +446,7 @@ public class WebConnact : MonoBehaviour private async Task QueryLatestMassacre(string token) { var headers = CreateHeaders(token); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", headers); Debug.Log("查询最近大屠杀响应: " + response); } @@ -459,7 +459,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", body, headers); Debug.Log("逃亡房间详情响应: " + response); } @@ -474,7 +474,7 @@ public class WebConnact : MonoBehaviour ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); } @@ -487,7 +487,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers); Debug.Log("查询击杀信息响应: " + response); } @@ -500,7 +500,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); } @@ -517,7 +517,7 @@ public class WebConnact : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } // Update 方法保留,但当前没有需要的功能 @@ -545,7 +545,7 @@ public class WebConnact : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法 @@ -677,7 +677,7 @@ public class WebConnact : MonoBehaviour private async Task QueryLatestMassacre(string token) { var headers = CreateHeaders(token); - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", headers); Debug.Log("查询最近大屠杀响应: " + response); } @@ -690,7 +690,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", body, headers); Debug.Log("逃亡房间详情响应: " + response); } @@ -705,7 +705,7 @@ public class WebConnact : MonoBehaviour ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); } @@ -718,7 +718,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers); Debug.Log("查询击杀信息响应: " + response); } @@ -731,7 +731,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); } @@ -748,7 +748,7 @@ public class WebConnact : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ /*using System; @@ -771,7 +771,7 @@ public class WebConnact : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法 @@ -900,7 +900,7 @@ public class WebConnact : MonoBehaviour //private async Task QueryLatestMassacre() //{ // var headers = CreateHeaders(); - // string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + // string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", headers); // Debug.Log("查询最近大屠杀响应: " + response); //} @@ -913,7 +913,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", body, headers); Debug.Log("逃亡房间详情响应: " + response); } @@ -928,7 +928,7 @@ public class WebConnact : MonoBehaviour ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); } @@ -941,7 +941,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers); Debug.Log("查询击杀信息响应: " + response); } @@ -954,7 +954,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); } @@ -971,7 +971,7 @@ public class WebConnact : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } }*/ using System; @@ -991,7 +991,7 @@ public class WebConnact : MonoBehaviour LoginAndGetToken.OnTokenReceived += HandleTokenReceived; // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; } // 当接收到 token 时触发此方法,仅保存 token @@ -1132,13 +1132,13 @@ public class WebConnact : MonoBehaviour Debug.Log("购买商品响应: " + response); } - //// 查询最近的大屠杀 - //public async Task QueryLatestMassacre() - //{ - // var headers = CreateHeaders(); - // string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); - // Debug.Log("查询最近大屠杀响应: " + response); - //} + // 查询最近的大屠杀 + public async Task QueryLatestMassacre() + { + var headers = CreateHeaders(); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", headers); + Debug.Log("查询最近大屠杀响应====================================================================================: " + response); + } // 查询逃亡房间详情 public async Task QueryEscapeRoomDetails() @@ -1149,7 +1149,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryEscapeRoomList", "POST", body, headers); Debug.Log("逃亡房间详情响应: " + response); } @@ -1164,7 +1164,7 @@ public class WebConnact : MonoBehaviour ""bet"": 100, ""roomNo"": 1 }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers); Debug.Log("用户下注响应: " + response); } @@ -1177,7 +1177,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers); Debug.Log("查询击杀信息响应: " + response); } @@ -1190,7 +1190,7 @@ public class WebConnact : MonoBehaviour ""userId"": 106, ""escapeId"": {escapeId} }}"; - string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryUserBetResult", "POST", body, headers); Debug.Log("查询用户下注结果响应: " + response); } @@ -1213,7 +1213,7 @@ public class WebConnact : MonoBehaviour { // 注销监听事件,避免内存泄漏 LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; } } diff --git a/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs b/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs deleted file mode 100644 index 5eed136..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs +++ /dev/null @@ -1,285 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Newtonsoft.Json; -using System.Threading.Tasks; - -/*public class selectGameEscape512 : MonoBehaviour -{ - public static selectGameEscape512 instance; - public int gameEscapeId; - public int carrySeconds; - // 定义一个事件,当 gameEscapeId 被更新时触发 - public static event Action OnGameEscapeIdUpdated; - - - - void Start() - { - instance=this; - - // 由于除登录注册外的其他方法,都需要登录后返回的token - // 因此登录不在此发送请求(同时) - // 采用监听和事件回调的方法,只有监听到登录和token返回时,才运行其他方法 - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - // 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - } - - private string token; // 用于保存收到的 token - - void HandleTokenReceived(string token) - { - // 使用 token - this.token = token; - Debug.Log("HandleTokenReceived监听:" + token); - StartCoroutine(GameEscapeRoutine(token)); // 启动协程,每2秒调用一次gameEscape - } - void HandleGameEscapeIdUpdated(int newGameEscapeId) - { - Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId); - // 在这里添加你想要执行的逻辑 - } - - // 创建一个IEnumerator的协程 - IEnumerator GameEscapeRoutine(string token) - { - while (true) // 无限循环来实现每2秒发送一次请求 - { - yield return new WaitForSeconds(2f); // 每2秒暂停一次 - yield return gameEscape(token); // 调用gameEscape方法 - } - yield return null; - } - - public async Task gameEscape(string token) - { - // 用来给请求头赋值 - 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/gameEscape/queryLatest", "POST", "{}", head51); - Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); // 查询最近一场大逃亡游戏详情: - - // 解析JSON数据 - string json = response51; - Response response = JsonConvert.DeserializeObject(json); - - if (response != null && response.code == 200 && response.data != null) - { - gameEscapeId = response.data.gameEscapeModel.id; - //Debug.Log("解析成功,id为: " + gameEscapeId); - carrySeconds= response.data.carrySeconds; - // 触发事件,通知所有订阅者 - OnGameEscapeIdUpdated?.Invoke(gameEscapeId); - } - else - { - Debug.LogError("解析失败或响应错误"); - } - } - - void OnDestroy() - { - // 取消监听,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - } - - // Update is called once per frame - void Update() - { - - } - - [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; // 数据对象 - } - -}*/ - - - -public class selectGameEscape512 : MonoBehaviour -{ - - public int gameEscapeId; - public int carrySeconds; - - - - // 定义一个事件,当 gameEscapeId 被更新时触发 - public static event Action OnGameEscapeIdUpdated; - - private string token; // 用于保存收到的 token - - void Start() - { - - - // 监听登录获取 token - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - } - - void HandleTokenReceived(string token) - { - this.token = token; - Debug.Log("HandleTokenReceived监听:" + token); - StartCoroutine(GameEscapeRoutine(token)); // 启动协程,每2秒调用一次gameEscape - } - - void HandleGameEscapeIdUpdated(int newGameEscapeId) - { - Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId); - } - - IEnumerator GameEscapeRoutine(string token) - { - while (true) - { - yield return new WaitForSeconds(2f); // 每2秒暂停一次 - yield return gameEscape(token); // 调用gameEscape方法 - } - yield return null; - } - - public async Task gameEscape(string token) - { - // 用来给请求头赋值 - string Authorization = token; - - // 设置请求头 - Dictionary head51 = new Dictionary - { - { "Authorization", Authorization } - }; - - // 发送请求并接收响应 - string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); - Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); - - // 解析JSON数据为 Response 对象 - Response response = JsonConvert.DeserializeObject(response51); - - 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) - { - int roomNo = room.roomNo; - float roomBeansCoin = room.roomBeansCoin; - - Debug.Log($"Room No: {roomNo}, Room Beans Coin: {roomBeansCoin}"); - } - - // 触发事件,通知所有订阅者 - OnGameEscapeIdUpdated?.Invoke(gameEscapeId); - } - else - { - Debug.LogError("解析失败或响应错误"); - } - } - - void OnDestroy() - { - // 取消监听,避免内存泄漏 - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - } - - // 数据类 - [Serializable] - public class GameEscapeModel - { - public int id; // 游戏 ID - 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; - } - - [Serializable] - public class GameEscapeRoomResponseVo - { - public int escapeId; // 逃脱游戏的ID - public int roomNo; // 房间号 - public float roomBeansCoin; // 房间中豆币数量 - } - - [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; // 数据对象 - } -} - - diff --git a/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs.meta b/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs.meta deleted file mode 100644 index d5f8bbf..0000000 --- a/TheStrongestSnail/Assets/Scripts/Login/selectGameEscape512.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b7936430f01cc8343a1e62fc2052a12b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: