预定演练接口完成

This commit is contained in:
HuangZiBo 2024-11-30 10:23:05 +08:00
parent b0682d1f74
commit 0259ecde77
9 changed files with 303 additions and 115 deletions

View File

@ -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<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+Global.global.loginResponse.data.access_token },
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//模板设备绑定
public async Task<BindMaterial> 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<BindMaterial>(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;//++++++++++++++++++++++++++++++++++++
}

View File

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

View File

@ -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<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+Global.global.loginResponse.data.access_token },
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//模板NPC绑定
public async Task<BindNPC> 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<BindNPC>(response);
return serverData;
}
}
//=========请求体===================================================================
public class BindNPCBody
{
string templateId;//===============必须
NpcList[] npcList;//见createTemplate.cs第37行//=========必须
}
//==========返回=============================
public class BindNPC : Response
{
public string data;//++++++++++++++++++++++++++++++++++++
}

View File

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

View File

@ -1,6 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
public class bindPlayer : MonoBehaviour public class bindPlayer : MonoBehaviour
@ -28,14 +29,15 @@ public class bindPlayer : MonoBehaviour
//친겼鯤소곬땍 //친겼鯤소곬땍
public async void BindPlayer(bindPlayerBody bindPlayerBody) public async Task<BindPlayer> BindPlayer(bindPlayerBody bindPlayerBody)
{ {
bindPlayerBody bindPlayerBody1 = new bindPlayerBody(); //bindPlayerBody bindPlayerBody1 = new bindPlayerBody();
bindPlayerBody1 = 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); Debug.Log("친겼鯤소곬땍: " + response);
BindPlayer serverData = JsonConvert.DeserializeObject<BindPlayer>(response); BindPlayer serverData = JsonConvert.DeserializeObject<BindPlayer>(response);
return serverData;
} }
} }
//=====헝헹竟==================================================================================== //=====헝헹竟====================================================================================
@ -44,3 +46,8 @@ public class bindPlayerBody
string templateId;//===============극伎 string templateId;//===============극伎
PlayerList[] playerList;//숨createTemplate.cs뒤37契//=========극伎 PlayerList[] playerList;//숨createTemplate.cs뒤37契//=========극伎
} }
//===============================================================================================
public class BindPlayer : Response
{
public string data;
}

View File

@ -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<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(Global.global.loginResponse.data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+Global.global.loginResponse.data.access_token },
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//提交预定演练模板
public async Task<SubmitTemplate> 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<SubmitTemplate>(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;//++++++++++++++++++++++++++++++++++++
}

View File

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

View File

@ -156,22 +156,22 @@ public class loginData
// public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应 // public string roleAttributions; // 与 JSON 中的 "roleAttributions" 字段对应
//} //}
//=================================================================== //===================================================================
public class BindPlayer:Response //public class BindPlayer:Response
{ //{
public string data; // public string data;
} //}
//============================================================= //=============================================================
public class BindNPC : Response //public class BindNPC : Response
{ //{
public string data;//++++++++++++++++++++++++++++++++++++ // public string data;//++++++++++++++++++++++++++++++++++++
} //}
//==================================================== //====================================================
public class BindMaterial : Response //public class BindMaterial : Response
{ //{
public string data;//++++++++++++++++++++++++++++++++++++ // public string data;//++++++++++++++++++++++++++++++++++++
} //}
//=================================================== //===================================================
public class SubmitTemplate : Response //public class SubmitTemplate : Response
{ //{
public string data;//++++++++++++++++++++++++++++++++++++ // public string data;//++++++++++++++++++++++++++++++++++++
} //}

View File

@ -112,6 +112,7 @@ public class login : MonoBehaviour
token = serverData.data.access_token; token = serverData.data.access_token;
Debug.Log("===========" + serverData.data.isCreater); Debug.Log("===========" + serverData.data.isCreater);
} }
}
//삿혤친겼죗깊 //삿혤친겼죗깊
//public async void TemplaRst() //public async void TemplaRst()
//{ //{
@ -253,108 +254,107 @@ public class login : MonoBehaviour
//} //}
//친겼鯤소곬땍 //친겼鯤소곬땍
public async void BindPlayer() //public async void BindPlayer()
{ //{
string templateId = "1111"; // string templateId = "1111";
string userId = "1"; // string userId = "1";
string roleId = "1"; // string roleId = "1";
string birthAreaId = "11"; // string birthAreaId = "11";
string chargeAreaId = "2"; // string chargeAreaId = "2";
string body = $@" // string body = $@"
{{ //{{
""templateId"": ""{templateId}"", // ""templateId"": ""{templateId}"",
""playerList"": [ // ""playerList"": [
{{ // {{
""userId"": ""{userId}"", // ""userId"": ""{userId}"",
""roleId"": ""{roleId}"", // ""roleId"": ""{roleId}"",
""birthAreaId"": ""{birthAreaId}"", // ""birthAreaId"": ""{birthAreaId}"",
""chargeAreaId"": ""{chargeAreaId}"" // ""chargeAreaId"": ""{chargeAreaId}""
}} // }}
] // ]
}}"; //}}";
string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", body, CreateHeaders()); // string response = await web.SendRequest(web.URL + "/game/gameTemplate/player", "POST", body, CreateHeaders());
Debug.Log("친겼鯤소곬땍: " + response); // Debug.Log("친겼鯤소곬땍: " + response);
BindPlayer serverData = JsonConvert.DeserializeObject<BindPlayer>(response); // BindPlayer serverData = JsonConvert.DeserializeObject<BindPlayer>(response);
} //}
//친겼NPC곬땍 ////친겼NPC곬땍
public async void BindNPC() //public async void BindNPC()
{ //{
string templateId = "1111"; // string templateId = "1111";
string npcId = "1"; // string npcId = "1";
string areaId = "1"; // string areaId = "1";
int npcNum = 1; // int npcNum = 1;
//string chargeAreaId = "2"; // //string chargeAreaId = "2";
string body = $@" // string body = $@"
{{ //{{
""templateId"": ""{templateId}"", // ""templateId"": ""{templateId}"",
""npcList"": [ // ""npcList"": [
{{ // {{
""npcId"": ""{npcId}"", // ""npcId"": ""{npcId}"",
""areaId"": ""{areaId}"", // ""areaId"": ""{areaId}"",
""npcNum"": ""{npcNum}"" // ""npcNum"": ""{npcNum}""
}} // }}
] // ]
}}"; //}}";
string response = await web.SendRequest(web.URL + "/game/gameTemplate/npc", "POST", body, CreateHeaders()); // string response = await web.SendRequest(web.URL + "/game/gameTemplate/npc", "POST", body, CreateHeaders());
Debug.Log("친겼NPC곬땍: " + response); // Debug.Log("친겼NPC곬땍: " + response);
BindNPC serverData = JsonConvert.DeserializeObject<BindNPC>(response); // BindNPC serverData = JsonConvert.DeserializeObject<BindNPC>(response);
} //}
//친겼<ECB99C>구곬땍 ////친겼<ECB99C>구곬땍
public async void BindMaterial() //public async void BindMaterial()
{ //{
string templateId = "1111"; // string templateId = "1111";
string materialId = "1"; // string materialId = "1";
int num = 0; // int num = 0;
//string chargeAreaId = "2"; // //string chargeAreaId = "2";
string body = $@" // string body = $@"
{{ //{{
""templateId"": ""{templateId}"", // ""templateId"": ""{templateId}"",
""materialList"": [ // ""materialList"": [
{{ // {{
""materialId"": ""{materialId}"", // ""materialId"": ""{materialId}"",
""num"": ""{num}"" // ""num"": ""{num}""
}} // }}
] // ]
}}"; //}}";
string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", body, CreateHeaders()); // string response = await web.SendRequest(web.URL + "/game/gameTemplate/material", "POST", body, CreateHeaders());
Debug.Log("친겼<ECB99C>구곬땍: " + response); // Debug.Log("친겼<ECB99C>구곬땍: " + response);
BindMaterial serverData = JsonConvert.DeserializeObject<BindMaterial>(response); // BindMaterial serverData = JsonConvert.DeserializeObject<BindMaterial>(response);
if (serverData.data == null) // if (serverData.data == null)
{ // {
Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); // Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
} // }
Debug.Log(serverData.data); // Debug.Log(serverData.data);
} //}
//瓊슥渡땍蘿족친겼 // //瓊슥渡땍蘿족친겼
public async void SubmitTemplate() // public async void SubmitTemplate()
{ // {
string templateId = "1111"; // string templateId = "1111";
string reserveDate = "2024-11-22"; // string reserveDate = "2024-11-22";
// int num = 0; // // int num = 0;
//string chargeAreaId = "2"; // //string chargeAreaId = "2";
string body = $@" // string body = $@"
{{ // {{
""templateId"": ""{templateId}"", // ""templateId"": ""{templateId}"",
""reserveDate"":""{reserveDate}"" // ""reserveDate"":""{reserveDate}""
}}"; // }}";
string response = await web.SendRequest(web.URL + "/game/gameRoom/reserve", "POST", body, CreateHeaders()); // string response = await web.SendRequest(web.URL + "/game/gameRoom/reserve", "POST", body, CreateHeaders());
Debug.Log("瓊슥渡땍蘿족친겼: " + response); // Debug.Log("瓊슥渡땍蘿족친겼: " + response);
BindMaterial serverData = JsonConvert.DeserializeObject<BindMaterial>(response); // BindMaterial serverData = JsonConvert.DeserializeObject<BindMaterial>(response);
if (serverData.data == null) // if (serverData.data == null)
{ // {
Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); // Debug.Log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
} // }
Debug.Log(serverData.data); // Debug.Log(serverData.data);
} // }
//}
}