_xiaofang/xiaofang/Assets/Script/DirllInterface/getRoleList.cs

79 lines
2.8 KiB
C#
Raw Normal View History

2024-11-29 20:06:53 +08:00
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class getRoleList : MonoBehaviour
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public Dictionary<string, string> CreateHeaders()
{
2024-12-04 15:26:46 +08:00
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.data.access_token))
2024-11-29 20:06:53 +08:00
{
Debug.LogWarning("<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ<CDB7><CAB1>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
2024-12-04 15:26:46 +08:00
{ "Authorization","Bearer "+MyGlobal.global.loginResponse.data.access_token },
2024-11-29 20:06:53 +08:00
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//<2F><>ɫ<EFBFBD>б<EFBFBD>
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("<22><>ѯ<EFBFBD><D1AF>ɫ<EFBFBD>б<EFBFBD>: " + response);
RoleList serverData = JsonConvert.DeserializeObject<RoleList>(response);
// <20><><EFBFBD><EFBFBD><E9B7B4><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
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;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>Ľ<EFBFBD>ɫ<EFBFBD>б<EFBFBD>
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);
}
}
}
//====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>==========================================================================================
public class getRoleListBody
{
public string sceneId;//=====<3D><><EFBFBD><EFBFBD>
}
//====<3D><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>==========================================================================================
public class RoleList
{
public int code; // <20><> JSON <20>е<EFBFBD> "code" <20>ֶζ<D6B6>Ӧ
public string msg; // <20><> JSON <20>е<EFBFBD> "msg" <20>ֶζ<D6B6>Ӧ
public List<RoleData> data; // <20><> JSON <20>е<EFBFBD> "data" <20>ֶζ<D6B6>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>б<EFBFBD>
}
public class RoleData
{
public string id; // <20><> JSON <20>е<EFBFBD> "id" <20>ֶζ<D6B6>Ӧ
public string roleName; // <20><> JSON <20>е<EFBFBD> "roleName" <20>ֶζ<D6B6>Ӧ
public string sceneId; // <20><> JSON <20>е<EFBFBD> "sceneId" <20>ֶζ<D6B6>Ӧ
public int gameName; // <20><> JSON <20>е<EFBFBD> "gameName" <20>ֶζ<D6B6>Ӧ<EFBFBD><D3A6>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int <20><><EFBFBD><EFBFBD>
public string roleAttributions; // <20><> JSON <20>е<EFBFBD> "roleAttributions" <20>ֶζ<D6B6>Ӧ
}