502 lines
16 KiB
C#
502 lines
16 KiB
C#
|
|
|||
|
|
|||
|
using System;
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using UnityEngine.UI;
|
|||
|
/*public class selectQueryKill : MonoBehaviour
|
|||
|
{
|
|||
|
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
|
|||
|
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
|
|||
|
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
|
|||
|
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated<65><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
|
|||
|
public void HandleTokenReceived(string receivedToken)
|
|||
|
{
|
|||
|
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
LoadInitialData();
|
|||
|
//LoadGameEscapeData();
|
|||
|
//Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
|
|||
|
{
|
|||
|
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
await QueryKill();//==================================================================================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>κεط<CEB5><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>input.GetKeyDown.....<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public async void LoadInitialData()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
await QueryKill();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId <20><> token
|
|||
|
public async void selectQueryKill1()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (escapeId == -1)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
// <20><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD>
|
|||
|
await QueryKill();//=================================================================================================================================
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//===============================================================================================================================================================================================================================
|
|||
|
// <20><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ
|
|||
|
public async Task QueryKill()
|
|||
|
{
|
|||
|
var headers = CreateHeaders();
|
|||
|
string body = $@"
|
|||
|
{{
|
|||
|
""userId"": 106,
|
|||
|
""escapeId"": {escapeId}
|
|||
|
}}";
|
|||
|
string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers);
|
|||
|
Debug.Log("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
|
|||
|
}
|
|||
|
//===============================================================================================================================================================================================================================
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public Dictionary<string, string> CreateHeaders()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
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>
|
|||
|
{
|
|||
|
{ "Authorization", token }
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
|
|||
|
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
|
|||
|
}
|
|||
|
}*/
|
|||
|
|
|||
|
|
|||
|
//<2F>ɸ<EFBFBD>id<69><64>
|
|||
|
/*public class SelectQueryKill514 : MonoBehaviour
|
|||
|
{
|
|||
|
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
|
|||
|
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
|
|||
|
public int userId;//<2F>û<EFBFBD>Id;
|
|||
|
private string lastQueryKillResponse = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĻ<C2B5>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>ѯ<EFBFBD><D1AF>Ӧ
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD>İ<EFBFBD>ť=======================================================================================
|
|||
|
public Button queryKillButton;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
|
|||
|
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
|
|||
|
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
|
|||
|
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
|
|||
|
|
|||
|
// <20><><EFBFBD>谴ť<E8B0B4><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> OnQueryKillButtonClicked======================================================================
|
|||
|
if (queryKillButton != null)
|
|||
|
{
|
|||
|
queryKillButton.onClick.AddListener(OnQueryKillButtonClicked);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
|
|||
|
public void HandleTokenReceived(string receivedToken)
|
|||
|
{
|
|||
|
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
|
|||
|
|
|||
|
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
LoadInitialData();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
|
|||
|
{
|
|||
|
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
|
|||
|
|
|||
|
// <20>ڽ<EFBFBD><DABD>յ<EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("HandleGameEscapeIdUpdated <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public async void LoadInitialData()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("<22><>ʼ<EFBFBD><CABC><EFBFBD>صIJ<D8B5>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3B4A5B7><EFBFBD>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
|||
|
public async void OnQueryKillButtonClicked()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD> token <20><> escapeId <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (escapeId == -1)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("<22>û<EFBFBD><C3BB><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
HandleQueryKillResponse(lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ
|
|||
|
public async Task<string> QueryKill()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
if (escapeId == -1)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
var headers = CreateHeaders();
|
|||
|
string body = $@"
|
|||
|
{{
|
|||
|
""userId"": {userId},
|
|||
|
""escapeId"": {escapeId}
|
|||
|
}}";
|
|||
|
|
|||
|
Debug.Log("<22><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ...");
|
|||
|
string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers);
|
|||
|
Debug.Log("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
|
|||
|
return response; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public Dictionary<string, string> CreateHeaders()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
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>
|
|||
|
{
|
|||
|
{ "Authorization", token }
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> QueryKill <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
private void HandleQueryKillResponse(string response)
|
|||
|
{
|
|||
|
if (response.Contains("success"))
|
|||
|
{
|
|||
|
Debug.Log("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣʧ<CFA2>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + response);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
|
|||
|
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
|
|||
|
|
|||
|
// ȡ<><C8A1><EFBFBD><EFBFBD>ť<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=================================================================================================
|
|||
|
if (queryKillButton != null)
|
|||
|
{
|
|||
|
queryKillButton.onClick.RemoveListener(OnQueryKillButtonClicked);
|
|||
|
}
|
|||
|
}
|
|||
|
}*/
|
|||
|
//<2F><><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
public class SelectQueryKill514 : MonoBehaviour
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ģʽʵ<CABD><CAB5>
|
|||
|
public static SelectQueryKill514 Instance { get; private set; }
|
|||
|
|
|||
|
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
|
|||
|
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
|
|||
|
public int userId; // <20>û<EFBFBD> Id
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>Ϊȫ<CEAA>ֱ<EFBFBD><D6B1><EFBFBD>
|
|||
|
public int latestCode; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> code
|
|||
|
public string latestMessage; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>ʾ<EFBFBD><CABE>
|
|||
|
public int latestRoomNoKill; // <20><><EFBFBD><EFBFBD>ɱ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public int latestRoomNoRemain; // <20><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> JSON <20><>ӦΪ<D3A6>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
private string lastQueryKillResponse = null;
|
|||
|
|
|||
|
public Button queryKillButton; // <20><>ѯ<EFBFBD><D1AF>ť
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
// ʵ<>ֵ<EFBFBD><D6B5><EFBFBD>ģʽ
|
|||
|
if (Instance == null)
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
DontDestroyOnLoad(gameObject); // <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Destroy(gameObject); // ȷ<><C8B7>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB>ʵ<EFBFBD><CAB5>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
|
|||
|
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
|
|||
|
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
|
|||
|
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
|
|||
|
|
|||
|
// <20><><EFBFBD>谴ť<E8B0B4><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> OnQueryKillButtonClicked
|
|||
|
if (queryKillButton != null)
|
|||
|
{
|
|||
|
queryKillButton.onClick.AddListener(OnQueryKillButtonClicked);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
|
|||
|
public void HandleTokenReceived(string receivedToken)
|
|||
|
{
|
|||
|
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
|
|||
|
|
|||
|
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
LoadInitialData();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
|
|||
|
{
|
|||
|
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
|
|||
|
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
|
|||
|
|
|||
|
// <20>ڽ<EFBFBD><DABD>յ<EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("HandleGameEscapeIdUpdated <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public async void LoadInitialData()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("<22><>ʼ<EFBFBD><CABC><EFBFBD>صIJ<D8B5>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3B4A5B7><EFBFBD>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
|||
|
public async void OnQueryKillButtonClicked()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD> token <20><> escapeId <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (escapeId == -1)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
lastQueryKillResponse = await QueryKill();
|
|||
|
Debug.Log("<22>û<EFBFBD><C3BB><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + lastQueryKillResponse);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
HandleQueryKillResponse(lastQueryKillResponse);
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ
|
|||
|
public async Task<string> QueryKill()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>token δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
if (escapeId == -1)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
var headers = CreateHeaders();
|
|||
|
string body = $@"
|
|||
|
{{
|
|||
|
""userId"": {userId},
|
|||
|
""escapeId"": {escapeId}
|
|||
|
}}";
|
|||
|
|
|||
|
Debug.Log("<22><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ...");
|
|||
|
string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryKill", "POST", body, headers);
|
|||
|
Debug.Log("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
|
|||
|
HandleQueryKillResponse(response); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
return response; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
|
|||
|
public Dictionary<string, string> CreateHeaders()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(token))
|
|||
|
{
|
|||
|
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>
|
|||
|
{
|
|||
|
{ "Authorization", token }
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> QueryKill <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|||
|
private void HandleQueryKillResponse(string response)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC>Ӧ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
lastQueryKillResponse = response;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
ServerResponse serverResponse = JsonConvert.DeserializeObject<ServerResponse>(response);
|
|||
|
|
|||
|
if (serverResponse != null && serverResponse.code == 200)
|
|||
|
{
|
|||
|
Debug.Log("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
|
|||
|
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ֶ<EFBFBD>
|
|||
|
latestCode = serverResponse.code;
|
|||
|
latestMessage = serverResponse.message;
|
|||
|
|
|||
|
if (serverResponse.data != null)
|
|||
|
{
|
|||
|
latestRoomNoKill = serverResponse.data.roomNoKill;
|
|||
|
latestRoomNoRemain = serverResponse.data.roomNoRemain;
|
|||
|
|
|||
|
Debug.Log($"Room No Kill: {latestRoomNoKill}, Room No Remain: {latestRoomNoRemain}");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1>Ϣʧ<CFA2>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + response);
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Debug.LogWarning("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD><C9B1>Ϣ<EFBFBD><CFA2>Ӧʧ<D3A6><CAA7>: " + e.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
|
|||
|
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
|
|||
|
|
|||
|
// ȡ<><C8A1><EFBFBD><EFBFBD>ť<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (queryKillButton != null)
|
|||
|
{
|
|||
|
queryKillButton.onClick.RemoveListener(OnQueryKillButtonClicked);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD> JSON <20><><EFBFBD><EFBFBD>
|
|||
|
[Serializable]
|
|||
|
public class Data
|
|||
|
{
|
|||
|
public int roomNoKill; // <20><><EFBFBD><EFBFBD>ɱ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public int roomNoRemain; // <20><><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class ServerResponse
|
|||
|
{
|
|||
|
public int code; // <20><>Ӧ״̬<D7B4><CCAC>
|
|||
|
public string message; // <20><>ʾ<EFBFBD><CABE>
|
|||
|
public Data data; // <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
//ʹ<><CAB9>ʾ<EFBFBD><CABE>
|
|||
|
//public class AnotherClass : MonoBehaviour
|
|||
|
//{
|
|||
|
// void Start()
|
|||
|
// {
|
|||
|
// int code = SelectQueryKill514.Instance.latestCode;
|
|||
|
// string message = SelectQueryKill514.Instance.latestMessage;
|
|||
|
// int roomNoKill = SelectQueryKill514.Instance.latestRoomNoKill;
|
|||
|
// int roomNoRemain = SelectQueryKill514.Instance.latestRoomNoRemain;
|
|||
|
// string jsonResponse = SelectQueryKill514.Instance.lastQueryKillResponse;
|
|||
|
|
|||
|
// Debug.Log($"Code: {code}, Message: {message}, Room No Kill: {roomNoKill}, Room No Remain: {roomNoRemain}");
|
|||
|
// Debug.Log($"Original JSON Response: {jsonResponse}");
|
|||
|
// }
|
|||
|
//}
|