From 518340ebdb931a005d0cc17a0a44a44ba4536989 Mon Sep 17 00:00:00 2001 From: HuangZiBo <1278481331@qq.com> Date: Fri, 29 Nov 2024 20:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E5=AE=9A=E6=BC=94?= =?UTF-8?q?=E7=BB=83=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Script/DirllInterface/bindPlayer.cs | 46 ++++++ .../Script/DirllInterface/bindPlayer.cs.meta | 11 ++ .../Script/DirllInterface/getRoleList.cs | 79 +++++++++++ .../Script/DirllInterface/getRoleList.cs.meta | 11 ++ .../Script/DirllInterface/querySubjectList.cs | 61 +++++--- xiaofang/Assets/Script/login/Global.cs | 74 +++++----- xiaofang/Assets/Script/login/login.cs | 132 +++++++++--------- 7 files changed, 292 insertions(+), 122 deletions(-) create mode 100644 xiaofang/Assets/Script/DirllInterface/bindPlayer.cs create mode 100644 xiaofang/Assets/Script/DirllInterface/bindPlayer.cs.meta create mode 100644 xiaofang/Assets/Script/DirllInterface/getRoleList.cs create mode 100644 xiaofang/Assets/Script/DirllInterface/getRoleList.cs.meta diff --git a/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs new file mode 100644 index 00000000..5bc8a4f2 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class bindPlayer : MonoBehaviour +{ + + + + // 创建请求头,使用最新的 token + public Dictionary CreateHeaders() + { + + + if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + + return new Dictionary + { + { "Authorization","Bearer "+Global.global.loginResponse.data.access_token }, + {"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" } + }; + } + + + //模板玩家绑定 + public async void BindPlayer(bindPlayerBody bindPlayerBody) + { + bindPlayerBody bindPlayerBody1 = new bindPlayerBody(); + bindPlayerBody1 = bindPlayerBody; + + string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", JsonConvert.SerializeObject(bindPlayerBody1), CreateHeaders()); + Debug.Log("模板玩家绑定: " + response); + BindPlayer serverData = JsonConvert.DeserializeObject(response); + } +} +//=====请求体==================================================================================== +public class bindPlayerBody +{ + string templateId;//===============必须 + PlayerList[] playerList;//见createTemplate.cs第37行//=========必须 +} diff --git a/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs.meta b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs.meta new file mode 100644 index 00000000..5c6e05bb --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87dc9f5d8174c1d4f93225552d06fe21 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Script/DirllInterface/getRoleList.cs b/xiaofang/Assets/Script/DirllInterface/getRoleList.cs new file mode 100644 index 00000000..27baaec0 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/getRoleList.cs @@ -0,0 +1,79 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class getRoleList : MonoBehaviour +{ + + // 创建请求头,使用最新的 token + public Dictionary CreateHeaders() + { + + + if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + + return new Dictionary + { + { "Authorization","Bearer "+Global.global.loginResponse.data.access_token }, + {"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" } + }; + } + //角色列表 + public async void queryRoleList(string secneId) + { + getRoleListBody getRoleListBody = new getRoleListBody(); + getRoleListBody.sceneId = secneId;//============================================================================== + string response = await web.SendRequest(web.URL + "/game/role/list", "GET", JsonConvert.SerializeObject(getRoleListBody), CreateHeaders()); + Debug.Log("查询角色列表: " + response); + RoleList serverData = JsonConvert.DeserializeObject(response); + + // 检查反序列化结果 + if (serverData == null) + { + Debug.LogError("Failed to deserialize JSON. RoleList is null."); + return; + } + + if (serverData.data == null || serverData.data.Count == 0) + { + Debug.LogWarning("No role data found in the returned data."); + return; + } + + // 遍历反序列化后的角色列表 + foreach (var role in serverData.data) + { + //Debug.Log("Role ID: " + role.id); + //Debug.Log("Role Name: " + role.roleName); + //Debug.Log("Scene ID: " + role.sceneId); + //Debug.Log("Game Name: " + role.gameName); + //Debug.Log("Role Attributions: " + role.roleAttributions); + } + } +} +//====请求体========================================================================================== +public class getRoleListBody +{ + public string sceneId;//=====必须 +} +//====返回值解析数据类========================================================================================== +public class RoleList +{ + public int code; // 与 JSON 中的 "code" 字段对应 + public string msg; // 与 JSON 中的 "msg" 字段对应 + public List data; // 与 JSON 中的 "data" 字段对应,包含角色的列表 +} + +public class RoleData +{ + public string id; // 与 JSON 中的 "id" 字段对应 + public string roleName; // 与 JSON 中的 "roleName" 字段对应 + public string sceneId; // 与 JSON 中的 "sceneId" 字段对应 + public int gameName; // 与 JSON 中的 "gameName" 字段对应,注意这里是 int 类型 + public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应 +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/DirllInterface/getRoleList.cs.meta b/xiaofang/Assets/Script/DirllInterface/getRoleList.cs.meta new file mode 100644 index 00000000..45c25ab6 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/getRoleList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0c2be722e7906a4aba1cfe40098da13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Script/DirllInterface/querySubjectList.cs b/xiaofang/Assets/Script/DirllInterface/querySubjectList.cs index 5a0d99f5..1470423a 100644 --- a/xiaofang/Assets/Script/DirllInterface/querySubjectList.cs +++ b/xiaofang/Assets/Script/DirllInterface/querySubjectList.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using UnityEngine; public class querySubjectList : MonoBehaviour @@ -24,10 +25,8 @@ public class querySubjectList : MonoBehaviour }; } //查询演练科目信息列表 - public async void QueryDrillSubject() + public async Task QueryDrillSubject() { - - string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders()); Debug.Log("查询演练科目信息列表: " + response); @@ -38,34 +37,58 @@ public class querySubjectList : MonoBehaviour if (drillSubject == null) { Debug.LogError("Failed to deserialize JSON. DrillSubject is null."); - return; } if (drillSubject.data == null || drillSubject.data.Count == 0) { Debug.LogWarning("No subjects found in the returned data."); - return; } // 遍历反序列化后的 data 列表 foreach (var subject in drillSubject.data) { - Debug.Log("ID: " + subject.id); - Debug.Log("Scene Names: " + subject.sceneNames); - Debug.Log("Name: " + subject.name); - Debug.Log("Suit Version: " + subject.suitVersion); - Debug.Log("Type: " + subject.type); - Debug.Log("Description: " + subject.description); - Debug.Log("Price: " + subject.price); - Debug.Log("Company ID: " + subject.companyId); - Debug.Log("Status: " + subject.status); - Debug.Log("Delete Flag: " + subject.delFlag); - Debug.Log("Remark: " + subject.remark); - Debug.Log("Game Name: " + subject.gameName); - Debug.Log("OSS ID: " + subject.ossId); - Debug.Log("File List: " + subject.fileList); + //Debug.Log("ID: " + subject.id); + //Debug.Log("Scene Names: " + subject.sceneNames); + //Debug.Log("Name: " + subject.name); + //Debug.Log("Suit Version: " + subject.suitVersion); + //Debug.Log("Type: " + subject.type); + //Debug.Log("Description: " + subject.description); + //Debug.Log("Price: " + subject.price); + //Debug.Log("Company ID: " + subject.companyId); + //Debug.Log("Status: " + subject.status); + //Debug.Log("Delete Flag: " + subject.delFlag); + //Debug.Log("Remark: " + subject.remark); + //Debug.Log("Game Name: " + subject.gameName); + //Debug.Log("OSS ID: " + subject.ossId); + //Debug.Log("File List: " + subject.fileList); // 如果需要进一步处理字段,可以在这里进行 // 比如,将价格转换为数字计算,或根据特定类型执行逻辑 } + return drillSubject; } } +//======================================================================================================= +public class DrillSubject : Response +{ + [JsonProperty("data")] + public List data; // 确保字段名与 JSON 中的匹配 +} + +public class QueryDrillSubjectData +{ + public string id;// + public string[] sceneIds; + public string sceneNames; + public string name; + public string suitVersion; + public string type; + public string description; + public string price; + public string companyId; + public string status; + public string delFlag; + public string remark; + public string gameName; + public string ossId; + public string fileList; +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/login/Global.cs b/xiaofang/Assets/Script/login/Global.cs index 8e47f771..1ef6634d 100644 --- a/xiaofang/Assets/Script/login/Global.cs +++ b/xiaofang/Assets/Script/login/Global.cs @@ -114,47 +114,47 @@ public class loginData // public string fileSuffix { get; set; } //} //================================================================= -public class DrillSubject : Response -{ - [JsonProperty("data")] - public List data; // 确保字段名与 JSON 中的匹配 -} +//public class DrillSubject : Response +//{ +// [JsonProperty("data")] +// public List data; // 确保字段名与 JSON 中的匹配 +//} -public class QueryDrillSubjectData -{ - public string id; - public string[] sceneIds; - public string sceneNames; - public string name; - public string suitVersion; - public string type; - public string description; - public string price; - public string companyId; - public string status; - public string delFlag; - public string remark; - public string gameName; - public string ossId; - public string fileList; -} +//public class QueryDrillSubjectData +//{ +// public string id; +// public string[] sceneIds; +// public string sceneNames; +// public string name; +// public string suitVersion; +// public string type; +// public string description; +// public string price; +// public string companyId; +// public string status; +// public string delFlag; +// public string remark; +// public string gameName; +// public string ossId; +// public string fileList; +//} //=============================================================== -public class RoleList -{ - public int code; // 与 JSON 中的 "code" 字段对应 - public string msg; // 与 JSON 中的 "msg" 字段对应 - public List data; // 与 JSON 中的 "data" 字段对应,包含角色的列表 -} +//public class RoleList +//{ +// public int code; // 与 JSON 中的 "code" 字段对应 +// public string msg; // 与 JSON 中的 "msg" 字段对应 +// public List data; // 与 JSON 中的 "data" 字段对应,包含角色的列表 +//} -public class RoleData -{ - public string id; // 与 JSON 中的 "id" 字段对应 - public string roleName; // 与 JSON 中的 "roleName" 字段对应 - public string sceneId; // 与 JSON 中的 "sceneId" 字段对应 - public int gameName; // 与 JSON 中的 "gameName" 字段对应,注意这里是 int 类型 - public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应 -} +//public class RoleData +//{ +// public string id; // 与 JSON 中的 "id" 字段对应 +// public string roleName; // 与 JSON 中的 "roleName" 字段对应 +// public string sceneId; // 与 JSON 中的 "sceneId" 字段对应 +// public int gameName; // 与 JSON 中的 "gameName" 字段对应,注意这里是 int 类型 +// public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应 +//} //=================================================================== public class BindPlayer:Response { diff --git a/xiaofang/Assets/Script/login/login.cs b/xiaofang/Assets/Script/login/login.cs index 3fd2799c..346ed599 100644 --- a/xiaofang/Assets/Script/login/login.cs +++ b/xiaofang/Assets/Script/login/login.cs @@ -177,80 +177,80 @@ public class login : MonoBehaviour //} //查询演练科目信息列表 - public async void QueryDrillSubject() - { - string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders()); - Debug.Log("查询演练科目信息列表: " + response); + //public async void QueryDrillSubject() + //{ + // string response = await web.SendRequest(web.URL + "/game/subject/list", "GET", "", CreateHeaders()); + // Debug.Log("查询演练科目信息列表: " + response); - // 使用 Newtonsoft.Json 进行反序列化 - DrillSubject drillSubject = JsonConvert.DeserializeObject(response); + // // 使用 Newtonsoft.Json 进行反序列化 + // DrillSubject drillSubject = JsonConvert.DeserializeObject(response); - // 检查反序列化结果 - if (drillSubject == null) - { - Debug.LogError("Failed to deserialize JSON. DrillSubject is null."); - return; - } + // // 检查反序列化结果 + // if (drillSubject == null) + // { + // Debug.LogError("Failed to deserialize JSON. DrillSubject is null."); + // return; + // } - if (drillSubject.data == null || drillSubject.data.Count == 0) - { - Debug.LogWarning("No subjects found in the returned data."); - return; - } + // if (drillSubject.data == null || drillSubject.data.Count == 0) + // { + // Debug.LogWarning("No subjects found in the returned data."); + // return; + // } - // 遍历反序列化后的 data 列表 - foreach (var subject in drillSubject.data) - { - Debug.Log("ID: " + subject.id); - Debug.Log("Scene Names: " + subject.sceneNames); - Debug.Log("Name: " + subject.name); - Debug.Log("Suit Version: " + subject.suitVersion); - Debug.Log("Type: " + subject.type); - Debug.Log("Description: " + subject.description); - Debug.Log("Price: " + subject.price); - Debug.Log("Company ID: " + subject.companyId); - Debug.Log("Status: " + subject.status); - Debug.Log("Delete Flag: " + subject.delFlag); - Debug.Log("Remark: " + subject.remark); - Debug.Log("Game Name: " + subject.gameName); - Debug.Log("OSS ID: " + subject.ossId); - Debug.Log("File List: " + subject.fileList); - // 如果需要进一步处理字段,可以在这里进行 - // 比如,将价格转换为数字计算,或根据特定类型执行逻辑 - } - } + // // 遍历反序列化后的 data 列表 + // foreach (var subject in drillSubject.data) + // { + // Debug.Log("ID: " + subject.id); + // Debug.Log("Scene Names: " + subject.sceneNames); + // Debug.Log("Name: " + subject.name); + // Debug.Log("Suit Version: " + subject.suitVersion); + // Debug.Log("Type: " + subject.type); + // Debug.Log("Description: " + subject.description); + // Debug.Log("Price: " + subject.price); + // Debug.Log("Company ID: " + subject.companyId); + // Debug.Log("Status: " + subject.status); + // Debug.Log("Delete Flag: " + subject.delFlag); + // Debug.Log("Remark: " + subject.remark); + // Debug.Log("Game Name: " + subject.gameName); + // Debug.Log("OSS ID: " + subject.ossId); + // Debug.Log("File List: " + subject.fileList); + // // 如果需要进一步处理字段,可以在这里进行 + // // 比如,将价格转换为数字计算,或根据特定类型执行逻辑 + // } + //} - //角色列表 - public async void queryRoleList() - { - string body = "{\"sceneId\": \"1845704588547301377\"}"; - string response = await web.SendRequest(web.URL + "/game/role/list", "GET", body, CreateHeaders()); - Debug.Log("查询角色列表: " + response); - RoleList serverData = JsonConvert.DeserializeObject(response); + ////角色列表 + //public async void queryRoleList() + //{ + // string body = "{\"sceneId\": \"1845704588547301377\"}"; + // string response = await web.SendRequest(web.URL + "/game/role/list", "GET", body, CreateHeaders()); + // Debug.Log("查询角色列表: " + response); + // RoleList serverData = JsonConvert.DeserializeObject(response); - // 检查反序列化结果 - if (serverData == null) - { - Debug.LogError("Failed to deserialize JSON. RoleList is null."); - return; - } + // // 检查反序列化结果 + // if (serverData == null) + // { + // Debug.LogError("Failed to deserialize JSON. RoleList is null."); + // return; + // } - if (serverData.data == null || serverData.data.Count == 0) - { - Debug.LogWarning("No role data found in the returned data."); - return; - } + // if (serverData.data == null || serverData.data.Count == 0) + // { + // Debug.LogWarning("No role data found in the returned data."); + // return; + // } - // 遍历反序列化后的角色列表 - foreach (var role in serverData.data) - { - Debug.Log("Role ID: " + role.id); - Debug.Log("Role Name: " + role.roleName); - Debug.Log("Scene ID: " + role.sceneId); - Debug.Log("Game Name: " + role.gameName); - Debug.Log("Role Attributions: " + role.roleAttributions); - } - } + // // 遍历反序列化后的角色列表 + // foreach (var role in serverData.data) + // { + // Debug.Log("Role ID: " + role.id); + // Debug.Log("Role Name: " + role.roleName); + // Debug.Log("Scene ID: " + role.sceneId); + // Debug.Log("Game Name: " + role.gameName); + // Debug.Log("Role Attributions: " + role.roleAttributions); + // } + //} //模板玩家绑定 public async void BindPlayer()