50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
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;//++++++++++++++++++++++++++++++++++++
|
||
} |