登录跑通,注册界面拼好,等待后续更换UI

This commit is contained in:
五条悟 2024-11-12 11:06:38 +08:00
parent ed7788d6fb
commit 27ce2579f8
11 changed files with 2855 additions and 455 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ public class LoginAndGetToken : MonoBehaviour
private void OnEnable()
{
Login();
//Login();
}
public async void Login()
@ -26,7 +26,7 @@ public class LoginAndGetToken : MonoBehaviour
body.password = "123456";// + 123456;
body.verifyCode = 111111;
string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body));
Debug.Log("LoginAndGetToken되쩌:"+loginResponse);
//Debug.Log("LoginAndGetToken되쩌:"+loginResponse);
string token = getToken(loginResponse);
OnTokenReceived?.Invoke(token);
//되쩌헝헹//綠繫법

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2025f7f7c1180de42b4787409a30b15d
guid: 8ee1a43c8ad7f8c41bad48013bf5af49
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -13,14 +13,22 @@ public class logoPanel : MonoBehaviour
public InputField userNameField;
public InputField passwordField;
public InputField verifyCodeField;
public Button pwdBtn;
public Button yzmBtn;
public GameObject sjh;
public Image regImg;
public GameObject yzm;
public GameObject mm;
public GameObject zh;
public GameObject qrmm;
public GameObject yqm;
public GameObject logBtn;
public Button loginBtn;
public GameObject regbtn;
public Button rigistBtn;
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
@ -32,10 +40,18 @@ public class logoPanel : MonoBehaviour
loginBtn.onClick.AddListener(() => StartCoroutine(OnClickLoginBtn()));
rigistBtn.onClick.AddListener(OnClickRigistBtn);
}
private void OnClickRigistBtn()
{
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(true);
qrmm.gameObject.SetActive(true);
yqm.gameObject.SetActive(true);
logBtn.gameObject.SetActive(false);
regbtn.gameObject.SetActive(true);
regImg.gameObject.SetActive(true);
pwdBtn.gameObject.SetActive(false);
yzmBtn.gameObject.SetActive(false);
}
//µã»÷µÇ¼°´Å¥
@ -49,13 +65,17 @@ public class logoPanel : MonoBehaviour
};
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = UnityWebRequest.Post("http://121.40.42.41:8080/snail/user/login", jsonBody))
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/login", "POST"))
{
webRequest.SetRequestHeader("Content-Type", "application/json");
// 创建和设置处理程序
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.uploadHandler.contentType = "application/json";
webRequest.downloadHandler = new DownloadHandlerBuffer();
// 发送请求
yield return webRequest.SendWebRequest();
// 检查请求结果
if (webRequest.result == UnityWebRequest.Result.Success)
{
string loginResponse = webRequest.downloadHandler.text;
@ -70,25 +90,23 @@ public class logoPanel : MonoBehaviour
}
}
//点击验证码按钮
//点击验证码登录按钮
private void OnClickYzmBtn()
{
pwdBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position += new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(true);
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(false);
zh.gameObject.SetActive(false);
}
//点击密码按钮
//点击密码登录按钮
private void OnClickPwdBtn()
{
pwdBtn.transform.position += new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(false);
yzm.gameObject.SetActive(false);
mm.gameObject.SetActive(true);
zh.gameObject.SetActive(true);
}
}

View File

@ -5,9 +5,246 @@ using System.Xml.Linq;
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class WebConnact : MonoBehaviour
{
private string token; // 保存 token 以便在整个类中使用
void Start()
{
// 由于除登录注册外的其他方法都需要登录后返回的token
// 因此登录不在此发送请求(同时)
// 采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated
selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
void HandleTokenReceived(string receivedToken)
{
// 保存 token
token = receivedToken; // 将接收到的 token 保存在类变量中
//Debug.Log("HandleTokenReceived监听:" + token);
// 首次调用时,暂时没有 escapeId 可以传递,因此传 -1
Loding(token, -1);
}
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId);
// 在这里调用 Loding 方法并传递最新的 escapeId
Loding(token, newGameEscapeId);
}
// 传入 token 和更新后的 escapeId
public async void Loding(string token, int newGameEscapeId)
{
// 用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)请求头赋值: " + Authorization);
// 如果 newGameEscapeId 不是初始值(-1则使用它
int escapeId = newGameEscapeId != -1 ? newGameEscapeId : 0;
Debug.Log("使用最新的 escapeId: " + escapeId);
// 你剩下的网络请求逻辑
// 例如:在需要用到 escapeId 的地方直接使用它
//1.3,完善用户信息//已通过
User_InformationHead user = new User_InformationHead();
Dictionary<string, string> head13 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string UserNewInfoBody = @"
{
""nickName"": ""wulongxiao"",
""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"",
""gender"": 1,
""birthday"": ""2023-12-12 12:12:12""
}";
//打印 JSON 请求体,用于调试
Debug.Log("JSON Request Data: " + UserNewInfoBody);
string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13);
Debug.Log("1.3完善用户信息" + response13);
////1.4查询用户详情(新增)
Dictionary<string, string> head14 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string response14 = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", head14);
Debug.Log("1.4查询用户详情" + response14);
//2.1商城列表//已通过
Mall_List mall_virtual = new Mall_List();
mall_virtual.productType = 0;
mall_virtual.pageNo = 1;
mall_virtual.pageSize = 20;
string mall_virtualponse = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall_virtual));
Debug.Log("2.1商城列表:" + mall_virtualponse);
//2.1,商城列表//已通过
Mall_List mall = new Mall_List();
mall.productType = 1;
//mall.pageNo = 1;
//mall.pageSize = 20;//这两个属性是默认值可以省略不写默认是1跟20
string response21 = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall));
Debug.Log("2.1商城列表:" + response21);
//2.2,获取商城商品详情//已通过
Dictionary<string, string> head22 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
Product_Details product = new Product_Details();
product.productId = 1;
string response22 = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product), head22);
Debug.Log("JSON Request Data: " + JsonUtility.ToJson(product));
Debug.Log("2.2,获取商城商品详情" + response22);
//2.3,商品购买(无支付)//已通过
Mall_buy mall_Buy = new Mall_buy();
Dictionary<string, string> head23 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
mall_Buy.userId = 106;
mall_Buy.productId = 1;
string response23 = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy), head23);
Debug.Log("2.3,商品购买(无支付)" + response23);
//3.1,查询公告分页://已通过
Query_Announcement query_Announcement = new Query_Announcement();
query_Announcement.userId = 106;
query_Announcement.pageNo = 1;
query_Announcement.pageSize = 20;
string response31 = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement));
Debug.Log("3.1,查询公告分页:" + response31);
//3.2,查询公告详情://已通过
int AnnouncementId = 1;
string response32 = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId={AnnouncementId}", "GET");
Debug.Log("3.2,查询公告详情:" + response32);
//=================================================================================================================================
//4.1查询靓号池分页//已通过
Dictionary<string, string> head41 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
int orderByBeansCoin = 1;
string response41 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/page", "POST", JsonUtility.ToJson(orderByBeansCoin), head41);
Debug.Log("查询靓号池分页" + response41);
//=================================================================================================================================
//4.2购买欢乐豆//已通过
Dictionary<string, string> head42 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string buyCutePool = @"
{
""userId"": 106,
""cutePoolId"": 2
}";
//打印 JSON 请求体,用于调试
Debug.Log("JSON Request Data: " + buyCutePool);
string response42 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/buy", "POST", buyCutePool, head42);
Debug.Log("购买欢乐豆" + response42);
//============================================================================================================================
//5.1查询最近一场大屠杀
Dictionary<string, string> head51 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
// 使用最新的 escapeId 在请求体中
string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
Debug.Log("5.1查询最近一场大屠杀: " + response51);
//====================================================================================================================
// 5.1.2查询各大逃亡房间最新详情(高性能版):
Dictionary<string, string> head512 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string queryEscapeRoomListBody = $@"
{{
""userId"": 106,
""escapeId"": {escapeId}
}}";
string response512 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", queryEscapeRoomListBody, head512);
Debug.Log("5.1.2查询各大逃亡房间最新详情(高性能版): " + response512);
//5.1.3,用户下注:
Dictionary<string, string> head513 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string userBetBody = $@"
{{
""userId"": 106,
""escapeId"": {escapeId},
""bet"": 100,
""roomNo"":1
}}";
string response513 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", userBetBody, head513);
Debug.Log("5.1.3,用户下注:" + response513);
//5.1.4,查询击杀
Dictionary<string, string> head514 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string selectKill = $@"
{{
""userId"": 106,
""escapeId"": {escapeId}
}}";
string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", selectKill, head514);
Debug.Log("5.1.4,查询击杀:" + response514);
//5.1.5,查询结算
Dictionary<string, string> head515 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string queryUserBetResult = $@"
{{
""userId"": 106,
""escapeId"": {escapeId}
}}";
string response515 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", queryUserBetResult, head515);
Debug.Log("5.1.5,查询结算:" + response515);
}
void OnDestroy()
{
// 取消监听,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
// Update is called once per frame
void Update()
{
}
}
/*public class WebConnact : MonoBehaviour
{
void Start()
@ -16,25 +253,35 @@ public class WebConnact : MonoBehaviour
//因此登录不在此发送请求(同时)
//采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
//Loding();
//Loding();
// 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated
selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
void HandleTokenReceived(string token)
{
// 使用 token
//string loginToken=token;
Debug.Log("HandleTokenReceived:"+token);
Debug.Log("HandleTokenReceived监听:"+token);
Loding(token);
}
public async void Loding(string token)
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
//用来给请求头赋值
Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId);
// 在这里添加你想要执行的逻辑
}
// 传入 token 和更新后的 escapeId
public async void Loding(string token, int newGameEscapeId)
{
// 用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)"+Authorization);
Debug.Log("Loding(Authorization)请求头赋值" + Authorization);
// 如果 newGameEscapeId 不是初始值(-1则使用它
int escapeId = newGameEscapeId != -1 ? newGameEscapeId : 0;
Debug.Log("使用最新的 escapeId: " + escapeId);
//loginbody body = new loginbody();
//body.userName = "15151658596";// + 15151658596;
@ -54,72 +301,172 @@ public class WebConnact : MonoBehaviour
//登录请求//已通过
//1.3,完善用户信息
// User_InformationHead user = new User_InformationHead();
// Dictionary<string, string> head13 = new Dictionary<string, string>
////1.3,完善用户信息//已通过
////User_InformationHead user = new User_InformationHead();
//Dictionary<string, string> head13 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// user.nickName = "wulongxiao";
// user.headImg = "https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png";
// user.gender = "男";
// user.birthday = "20010506";
// string UserNewInfoBody = "{\"nickName\":\"wulongxiao\",\"headImg\":\"https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png\",\"gender\":\"男\",\"birthday\":\"20010506\"}";
// string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13);
// Debug.Log(response13);
//string UserNewInfoBody = @"
// {
// ""nickName"": ""wulongxiao"",
// ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"",
// ""gender"": 1,
// ""birthday"": ""2023-12-12 12:12:12""
// }";
////打印 JSON 请求体,用于调试
//Debug.Log("JSON Request Data: " + UserNewInfoBody);
//string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13);
//Debug.Log("1.3完善用户信息" + response13);
////1.4查询用户详情(新增)
//Dictionary<string, string> head14 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string response14 = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", head14);
//Debug.Log("1.4查询用户详情" + response14);
////2.1商城列表//已通过
//Mall_List mall_virtual = new Mall_List();
//mall_virtual.productType = 0;
//mall_virtual.pageNo = 1;
//mall_virtual.pageSize = 20;
//string mall_virtualponse = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall_virtual));
//Debug.Log(mall_virtualponse);
//Debug.Log("2.1商城列表:" + mall_virtualponse);
////2.1,商城列表//已通过
//Mall_List mall = new Mall_List();
//mall.productType = 1;
////mall.pageNo = 1;
////mall.pageSize = 20;//这两个属性是默认值可以省略不写默认是1跟20
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall));
//Debug.Log(response);
//string response21 = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall));
//Debug.Log("2.1商城列表:" + response21);
////2.2,获取商城商品详情//已通过
//Dictionary<string, string> head22 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//Product_Details product = new Product_Details();
//product.productId = 1;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product));
//Debug.Log(response);
//string response22 = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product), head22);
//Debug.Log("JSON Request Data: " + JsonUtility.ToJson(product));
//Debug.Log("2.2,获取商城商品详情" + response22);
////2.3,商品购买(无支付)//已通过
//Mall_buy mall_Buy = new Mall_buy();
//Dictionary<string, string> head23 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//mall_Buy.userId = 106;
//mall_Buy.productId = 1;
//string response23 = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy), head23);
//Debug.Log("2.3,商品购买(无支付)" + response23);
// Mall_buy mall_Buy = new Mall_buy();
//string Authorization = "7083e9cb0de74c9dbb3c02f37ec339b8";
// mall_Buy.userId = 106;
// mall_Buy.productId = 1;
// string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy),Authorization);
// Debug.Log(response);
////3.1,查询公告分页://已通过
//Query_Announcement query_Announcement = new Query_Announcement();
//query_Announcement.userId = 106;
//query_Announcement.pageNo = 1;
//query_Announcement.pageSize = 20;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement));
//Debug.Log(response);
//string response31 = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement));
//Debug.Log("3.1,查询公告分页:" + response31);
//string response = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId=${公告id}", "Get");
//Debug.Log(response);
////3.2,查询公告详情://已通过
//int AnnouncementId = 1;
//string response32 = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId={AnnouncementId}", "GET");
//Debug.Log("3.2,查询公告详情:" + response32);
////4.1查询靓号池分页//已通过
//Dictionary<string, string> head41 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//int orderByBeansCoin = 1;
//string response41 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/page", "POST", JsonUtility.ToJson(orderByBeansCoin), head41);
//Debug.Log("查询靓号池分页" + response41);
////4.2购买欢乐豆//已通过
//Dictionary<string, string> head42 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string buyCutePool = @"
// {
// ""userId"": 106,
// ""cutePoolId"": 2
// }";
////打印 JSON 请求体,用于调试
//Debug.Log("JSON Request Data: " + buyCutePool);
//string response42 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/buy", "POST", buyCutePool, head42);
//Debug.Log("购买欢乐豆" + response42);
//5.1查询最近一场大屠杀
// Dictionary<string, string> head51 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// //head.Add("Authorization", token);
// string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
// Debug.Log(response51);//查询最近一场大逃亡游戏详情:
//已通过
////5.1查询最近一场大屠杀//已通过
//Dictionary<string, string> head51 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
//Debug.Log("5.1查询最近一场大屠杀" + response51);//查询最近一场大逃亡游戏详情:
//===========================================getToken================================================================================
////5.1.2查询各大逃亡房间最新详情(高性能版)
//Dictionary<string, string> head512 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string queryEscapeRoomListBody = @"
// {
// ""userId"": 106,
// ""escapeId"": 24336
// }";
//string response512 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", queryEscapeRoomListBody, head512);
//Debug.Log("5.1.2查询各大逃亡房间最新详情(高性能版)" + response512);
////5.1.3,用户下注:
//Dictionary<string, string> head513 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string userBetBody = @"
// {
// ""userId"": 106,
// ""escapeId"": 24381,
// ""bet"": 100,
// ""roomNo"":1
// }";
//string response513 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", userBetBody, head513);
//Debug.Log("5.1.3,用户下注:" + response513);
//5.1.4,查询击杀
Dictionary<string, string> head514 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string selectKill = @"
{
""userId"": 106,
""escapeId"": {escapeId}
}";
string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", selectKill, head514);
Debug.Log("5.1.4,查询击杀:" + response514);
//////5.1.5,查询结算
//Dictionary<string, string> head515 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
//string queryUserBetResult = @"
// {
// ""userId"": 106,
// ""escapeId"": 24377
// }";
//string response515 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", queryUserBetResult, head515);
//Debug.Log("5.1.5,查询结算:" + response515);
//===========================================================================================================================
}
void OnDestroy()
@ -131,7 +478,7 @@ public class WebConnact : MonoBehaviour
{
}
}
}*/
[Serializable]
public class Search_room//登录和注册用
@ -142,7 +489,6 @@ public class Search_room//
}
//[Serializable]
//public class loginbody//登录和注册用
//{
@ -189,5 +535,9 @@ public class Mall_buy
}
[Serializable]
public class cutePoolPage {
public int orderByBeansCoin;
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 34ecfc23bb797c848943318a4441e0b6
guid: 9e50b3d02b729854e87c092afffd2a03
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,234 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Threading.Tasks;
public class selectGameEscape512 : MonoBehaviour
{
private int gameEscapeId;
// 定义一个事件,当 gameEscapeId 被更新时触发
public static event Action<int> OnGameEscapeIdUpdated;
void Start()
{
// 由于除登录注册外的其他方法都需要登录后返回的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(5f); // 每2秒暂停一次
yield return gameEscape(token); // 调用gameEscape方法
}
}
public async Task gameEscape(string token)
{
// 用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)请求头赋值" + Authorization);
// 5.1查询最近一场大屠杀
Dictionary<string, string> head51 = new Dictionary<string, string>
{
{ "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<Response>(json);
if (response != null && response.code == 200 && response.data != null)
{
gameEscapeId = response.data.gameEscapeModel.id;
Debug.Log("解析成功id为: " + gameEscapeId);
// 触发事件,通知所有订阅者
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<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // 房间信息列表
public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义
}
[Serializable]
public class Response
{
public int code; // 状态码
public string message; // 返回信息
public Data data; // 数据对象
}
}
/*public class selectGameEscape512 : MonoBehaviour
{
int gameEscapeId;
void Start()
{
// 由于除登录注册外的其他方法都需要登录后返回的token
// 因此登录不在此发送请求(同时)
// 采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
}
void HandleTokenReceived(string token)
{
// 使用 token
Debug.Log("HandleTokenReceived监听:" + token);
StartCoroutine(GameEscapeRoutine(token)); // 启动协程每2秒调用一次gameEscape
}
// 创建一个IEnumerator的协程
IEnumerator GameEscapeRoutine(string token)
{
while (true) // 无限循环来实现每2秒发送一次请求
{
yield return new WaitForSeconds(2f); // 每2秒暂停一次
yield return gameEscape(token); // 调用gameEscape方法
}
}
public async Task gameEscape(string token)
{
// 用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)请求头赋值" + Authorization);
// 5.1查询最近一场大屠杀
Dictionary<string, string> head51 = new Dictionary<string, string>
{
{ "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<Response>(json);
if (response != null && response.code == 200 && response.data != null)
{
gameEscapeId = response.data.gameEscapeModel.id;
Debug.Log("解析成功id为: " + 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<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // 房间信息列表
public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义
}
[Serializable]
public class Response
{
public int code; // 状态码
public string message; // 返回信息
public Data data; // 数据对象
}
}*/

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7936430f01cc8343a1e62fc2052a12b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fe572b1c84900a9488ac4f55917dfefa
guid: db50a6d583762ea45b20d705d0e068cd
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1 +1 @@
验证码手机号登录密码登录手机号验证码立刻登录获取验证码没有账号?立即点击注册
验证码手机号登录密码登录手机号验证码立刻登录获取验证码没有账号?立即点击注册确认密码邀请游戏