diff --git a/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs b/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs new file mode 100644 index 00000000..b81fe6b9 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class bindMaterial : 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 Task BindMaterial(BindMaterialBody _bindMaterialBody) + { + + string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", JsonConvert.SerializeObject(_bindMaterialBody), CreateHeaders()); + Debug.Log("模板设备绑定: " + response); + BindMaterial serverData = JsonConvert.DeserializeObject(response); + if (serverData.data == null) + { + Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + } + Debug.Log(serverData.data); + return serverData; + } +} +//=====请求体=============================================== +public class BindMaterialBody +{ + public string templateId; + MaterialList[] materialList; +} +//=====返回=============================================== +public class BindMaterial : Response +{ + public string data;//++++++++++++++++++++++++++++++++++++ +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs.meta b/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs.meta new file mode 100644 index 00000000..74e011d1 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindMaterial.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7e8bc78a7741d14ca2051180d8350c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Script/DirllInterface/bindNPC.cs b/xiaofang/Assets/Script/DirllInterface/bindNPC.cs new file mode 100644 index 00000000..bb2b89d9 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindNPC.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class bindNPC : 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" } + }; + } + //模板NPC绑定 + public async Task BindNPC(BindNPCBody _bindNPCBody) + { + //BindNPCBody bindNPCBody = new BindNPCBody(); + //bindNPCBody = _bindNPCBody; + string response = await web.SendRequest(web.URL + "/game/gameTemplate/npc", "POST", JsonConvert.SerializeObject(_bindNPCBody), CreateHeaders()); + Debug.Log("模板NPC绑定: " + response); + BindNPC serverData = JsonConvert.DeserializeObject(response); + return serverData; + } +} +//=========请求体=================================================================== +public class BindNPCBody +{ + string templateId;//===============必须 + NpcList[] npcList;//见createTemplate.cs第37行//=========必须 +} + + +//==========返回============================= +public class BindNPC : Response +{ + public string data;//++++++++++++++++++++++++++++++++++++ +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/DirllInterface/bindNPC.cs.meta b/xiaofang/Assets/Script/DirllInterface/bindNPC.cs.meta new file mode 100644 index 00000000..761b2b7c --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/bindNPC.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 55a6f185d418b4f4fb02c65aaa7d2315 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs index 5bc8a4f2..0c883484 100644 --- a/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs +++ b/xiaofang/Assets/Script/DirllInterface/bindPlayer.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using UnityEngine; public class bindPlayer : MonoBehaviour @@ -28,14 +29,15 @@ public class bindPlayer : MonoBehaviour //模板玩家绑定 - public async void BindPlayer(bindPlayerBody bindPlayerBody) + public async Task BindPlayer(bindPlayerBody bindPlayerBody) { - bindPlayerBody bindPlayerBody1 = new bindPlayerBody(); - bindPlayerBody1 = bindPlayerBody; + //bindPlayerBody bindPlayerBody1 = new bindPlayerBody(); + //bindPlayerBody1 = bindPlayerBody; - string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", JsonConvert.SerializeObject(bindPlayerBody1), CreateHeaders()); + string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", JsonConvert.SerializeObject(bindPlayerBody), CreateHeaders()); Debug.Log("模板玩家绑定: " + response); BindPlayer serverData = JsonConvert.DeserializeObject(response); + return serverData; } } //=====请求体==================================================================================== @@ -44,3 +46,8 @@ public class bindPlayerBody string templateId;//===============必须 PlayerList[] playerList;//见createTemplate.cs第37行//=========必须 } +//=============================================================================================== +public class BindPlayer : Response +{ + public string data; +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs b/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs new file mode 100644 index 00000000..6ff517ef --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs @@ -0,0 +1,48 @@ +using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class submitTemplate : 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 Task SubmitTemplate(submitTemplateBody _submitTemplateBody) + { + string response = await web.SendRequest(web.URL + "/game/gameRoom/reserve", "POST", JsonConvert.SerializeObject(_submitTemplateBody), CreateHeaders()); + Debug.Log("提交预定演练模板: " + response); + SubmitTemplate serverData = JsonConvert.DeserializeObject(response); + if (serverData.data == null) + { + Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + } + Debug.Log(serverData.data); + return serverData; + } +} +//========请求体======================================== +public class submitTemplateBody +{ + public string templateId; + public string reserveDate; +} +//===========返回值============================================ +public class SubmitTemplate : Response +{ + public string data;//++++++++++++++++++++++++++++++++++++ +} \ No newline at end of file diff --git a/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs.meta b/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs.meta new file mode 100644 index 00000000..f4cc6029 --- /dev/null +++ b/xiaofang/Assets/Script/DirllInterface/submitTemplate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5401326285f565747ba6a116a034f249 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/Script/login/Global.cs b/xiaofang/Assets/Script/login/Global.cs index bd801cc6..f39e95c8 100644 --- a/xiaofang/Assets/Script/login/Global.cs +++ b/xiaofang/Assets/Script/login/Global.cs @@ -156,22 +156,22 @@ public class loginData // public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应 //} //=================================================================== -public class BindPlayer:Response -{ - public string data; -} +//public class BindPlayer:Response +//{ +// public string data; +//} //============================================================= -public class BindNPC : Response -{ - public string data;//++++++++++++++++++++++++++++++++++++ -} +//public class BindNPC : Response +//{ +// public string data;//++++++++++++++++++++++++++++++++++++ +//} //==================================================== -public class BindMaterial : Response -{ - public string data;//++++++++++++++++++++++++++++++++++++ -} +//public class BindMaterial : Response +//{ +// public string data;//++++++++++++++++++++++++++++++++++++ +//} //=================================================== -public class SubmitTemplate : Response -{ - public string data;//++++++++++++++++++++++++++++++++++++ -} \ No newline at end of file +//public class SubmitTemplate : Response +//{ +// public string data;//++++++++++++++++++++++++++++++++++++ +//} \ No newline at end of file diff --git a/xiaofang/Assets/Script/login/login.cs b/xiaofang/Assets/Script/login/login.cs index 346ed599..2cd941cb 100644 --- a/xiaofang/Assets/Script/login/login.cs +++ b/xiaofang/Assets/Script/login/login.cs @@ -112,6 +112,7 @@ public class login : MonoBehaviour token = serverData.data.access_token; Debug.Log("===========" + serverData.data.isCreater); } +} //获取模板列表 //public async void TemplaRst() //{ @@ -253,108 +254,107 @@ public class login : MonoBehaviour //} //模板玩家绑定 - public async void BindPlayer() - { - string templateId = "1111"; - string userId = "1"; - string roleId = "1"; - string birthAreaId = "11"; - string chargeAreaId = "2"; + //public async void BindPlayer() + //{ + // string templateId = "1111"; + // string userId = "1"; + // string roleId = "1"; + // string birthAreaId = "11"; + // string chargeAreaId = "2"; - string body = $@" - {{ - ""templateId"": ""{templateId}"", - ""playerList"": [ - {{ - ""userId"": ""{userId}"", - ""roleId"": ""{roleId}"", - ""birthAreaId"": ""{birthAreaId}"", - ""chargeAreaId"": ""{chargeAreaId}"" - }} - ] - }}"; + // string body = $@" + //{{ + // ""templateId"": ""{templateId}"", + // ""playerList"": [ + // {{ + // ""userId"": ""{userId}"", + // ""roleId"": ""{roleId}"", + // ""birthAreaId"": ""{birthAreaId}"", + // ""chargeAreaId"": ""{chargeAreaId}"" + // }} + // ] + //}}"; - string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", body, CreateHeaders()); - Debug.Log("模板玩家绑定: " + response); - BindPlayer serverData = JsonConvert.DeserializeObject(response); - } - //模板NPC绑定 - public async void BindNPC() - { - string templateId = "1111"; - string npcId = "1"; - string areaId = "1"; - int npcNum = 1; - //string chargeAreaId = "2"; + // string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", body, CreateHeaders()); + // Debug.Log("模板玩家绑定: " + response); + // BindPlayer serverData = JsonConvert.DeserializeObject(response); + //} + ////模板NPC绑定 + //public async void BindNPC() + //{ + // string templateId = "1111"; + // string npcId = "1"; + // string areaId = "1"; + // int npcNum = 1; + // //string chargeAreaId = "2"; - string body = $@" - {{ - ""templateId"": ""{templateId}"", - ""npcList"": [ - {{ - ""npcId"": ""{npcId}"", - ""areaId"": ""{areaId}"", - ""npcNum"": ""{npcNum}"" - }} - ] - }}"; + // string body = $@" + //{{ + // ""templateId"": ""{templateId}"", + // ""npcList"": [ + // {{ + // ""npcId"": ""{npcId}"", + // ""areaId"": ""{areaId}"", + // ""npcNum"": ""{npcNum}"" + // }} + // ] + //}}"; - string response = await web.SendRequest(web.URL + "/game/gameTemplate/npc", "POST", body, CreateHeaders()); - Debug.Log("模板NPC绑定: " + response); - BindNPC serverData = JsonConvert.DeserializeObject(response); - } - //模板设备绑定 - public async void BindMaterial() - { - string templateId = "1111"; - string materialId = "1"; - int num = 0; - //string chargeAreaId = "2"; + // string response = await web.SendRequest(web.URL + "/game/gameTemplate/npc", "POST", body, CreateHeaders()); + // Debug.Log("模板NPC绑定: " + response); + // BindNPC serverData = JsonConvert.DeserializeObject(response); + //} + ////模板设备绑定 + //public async void BindMaterial() + //{ + // string templateId = "1111"; + // string materialId = "1"; + // int num = 0; + // //string chargeAreaId = "2"; - string body = $@" - {{ - ""templateId"": ""{templateId}"", - ""materialList"": [ - {{ - ""materialId"": ""{materialId}"", - ""num"": ""{num}"" - }} - ] - }}"; + // string body = $@" + //{{ + // ""templateId"": ""{templateId}"", + // ""materialList"": [ + // {{ + // ""materialId"": ""{materialId}"", + // ""num"": ""{num}"" + // }} + // ] + //}}"; - string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", body, CreateHeaders()); - Debug.Log("模板设备绑定: " + response); - BindMaterial serverData = JsonConvert.DeserializeObject(response); - if (serverData.data == null) - { - Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - } - Debug.Log(serverData.data); - } + // string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", body, CreateHeaders()); + // Debug.Log("模板设备绑定: " + response); + // BindMaterial serverData = JsonConvert.DeserializeObject(response); + // if (serverData.data == null) + // { + // Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + // } + // Debug.Log(serverData.data); + //} - //提交预定演练模板 - public async void SubmitTemplate() - { - string templateId = "1111"; - string reserveDate = "2024-11-22"; - // int num = 0; - //string chargeAreaId = "2"; +// //提交预定演练模板 +// public async void SubmitTemplate() +// { +// string templateId = "1111"; +// string reserveDate = "2024-11-22"; +// // int num = 0; +// //string chargeAreaId = "2"; - string body = $@" - {{ - ""templateId"": ""{templateId}"", - ""reserveDate"":""{reserveDate}"" - }}"; - string response = await web.SendRequest(web.URL + "/game/gameRoom/reserve", "POST", body, CreateHeaders()); - Debug.Log("提交预定演练模板: " + response); - BindMaterial serverData = JsonConvert.DeserializeObject(response); - if (serverData.data == null) - { - Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - } - Debug.Log(serverData.data); - } - -} +// string body = $@" +// {{ +// ""templateId"": ""{templateId}"", +// ""reserveDate"":""{reserveDate}"" +// }}"; +// string response = await web.SendRequest(web.URL + "/game/gameRoom/reserve", "POST", body, CreateHeaders()); +// Debug.Log("提交预定演练模板: " + response); +// BindMaterial serverData = JsonConvert.DeserializeObject(response); +// if (serverData.data == null) +// { +// Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); +// } +// Debug.Log(serverData.data); +// } +//}