235 lines
6.6 KiB
C#
235 lines
6.6 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
public class selectGameEscape512 : MonoBehaviour
|
|||
|
{
|
|||
|
private int gameEscapeId;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> gameEscapeId <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
public static event Action<int> OnGameEscapeIdUpdated;
|
|||
|
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// <20><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>¼ע<C2BC><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>¼<EFBFBD>ص<F3B7B5BB>token
|
|||
|
// <20><><EFBFBD>˵<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ڴ˷<DAB4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1>
|
|||
|
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD><D8B5>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>token<65><6E><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> gameEscapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
|
|||
|
selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
|
|||
|
}
|
|||
|
|
|||
|
private string token; // <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD> token
|
|||
|
|
|||
|
void HandleTokenReceived(string token)
|
|||
|
{
|
|||
|
// ʹ<><CAB9> token
|
|||
|
this.token = token;
|
|||
|
Debug.Log("HandleTokenReceived<65><64><EFBFBD><EFBFBD>:" + token);
|
|||
|
StartCoroutine(GameEscapeRoutine(token)); // <20><><EFBFBD><EFBFBD>Э<EFBFBD>̣<EFBFBD>ÿ2<C3BF><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>gameEscape
|
|||
|
}
|
|||
|
void HandleGameEscapeIdUpdated(int newGameEscapeId)
|
|||
|
{
|
|||
|
Debug.Log("GameEscapeId <20>Ѹ<EFBFBD><D1B8><EFBFBD>Ϊ: " + newGameEscapeId);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫִ<D2AA>е<EFBFBD><D0B5><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IEnumerator<6F><72>Э<EFBFBD><D0AD>
|
|||
|
IEnumerator GameEscapeRoutine(string token)
|
|||
|
{
|
|||
|
while (true) // <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>ÿ2<C3BF>뷢<EFBFBD><EBB7A2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(5f); // ÿ2<C3BF><32><EFBFBD><EFBFBD>ͣһ<CDA3><D2BB>
|
|||
|
yield return gameEscape(token); // <20><><EFBFBD><EFBFBD>gameEscape<70><65><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public async Task gameEscape(string token)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ
|
|||
|
string Authorization = token;
|
|||
|
Debug.Log("Loding(Authorization)<29><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ" + Authorization);
|
|||
|
|
|||
|
// 5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ
|
|||
|
Dictionary<string, string> head51 = new Dictionary<string, string>
|
|||
|
{
|
|||
|
{ "Authorization", Authorization }, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩͷ
|
|||
|
};
|
|||
|
|
|||
|
string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
|
|||
|
Debug.Log("5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ(<28><><EFBFBD><EFBFBD>)" + response51); // <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>飺
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD>
|
|||
|
string json = response51;
|
|||
|
Response response = JsonConvert.DeserializeObject<Response>(json);
|
|||
|
|
|||
|
if (response != null && response.code == 200 && response.data != null)
|
|||
|
{
|
|||
|
gameEscapeId = response.data.gameEscapeModel.id;
|
|||
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>idΪ: " + gameEscapeId);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
OnGameEscapeIdUpdated?.Invoke(gameEscapeId);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("<22><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class GameEscapeModel
|
|||
|
{
|
|||
|
public int id; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷID
|
|||
|
public string gameNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class GameEscapeRoomResponseVo
|
|||
|
{
|
|||
|
public int escapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>ID
|
|||
|
public int roomNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class Data
|
|||
|
{
|
|||
|
public int carrySeconds; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public GameEscapeModel gameEscapeModel; // Ƕ<><EFBFBD>GameEscapeModel<65><6C><EFBFBD><EFBFBD>
|
|||
|
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>б<EFBFBD>
|
|||
|
public object gameEscapeUserModel; // <20>û<EFBFBD>ģ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>Ϊ<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class Response
|
|||
|
{
|
|||
|
public int code; // ״̬<D7B4><CCAC>
|
|||
|
public string message; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
public Data data; // <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*public class selectGameEscape512 : MonoBehaviour
|
|||
|
{
|
|||
|
int gameEscapeId;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// <20><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>¼ע<C2BC><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>¼<EFBFBD>ص<F3B7B5BB>token
|
|||
|
// <20><><EFBFBD>˵<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ڴ˷<DAB4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1>
|
|||
|
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD><D8B5>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>token<65><6E><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
|
|||
|
}
|
|||
|
|
|||
|
void HandleTokenReceived(string token)
|
|||
|
{
|
|||
|
// ʹ<><CAB9> token
|
|||
|
Debug.Log("HandleTokenReceived<65><64><EFBFBD><EFBFBD>:" + token);
|
|||
|
StartCoroutine(GameEscapeRoutine(token)); // <20><><EFBFBD><EFBFBD>Э<EFBFBD>̣<EFBFBD>ÿ2<C3BF><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>gameEscape
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IEnumerator<6F><72>Э<EFBFBD><D0AD>
|
|||
|
IEnumerator GameEscapeRoutine(string token)
|
|||
|
{
|
|||
|
while (true) // <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>ÿ2<C3BF>뷢<EFBFBD><EBB7A2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(2f); // ÿ2<C3BF><32><EFBFBD><EFBFBD>ͣһ<CDA3><D2BB>
|
|||
|
yield return gameEscape(token); // <20><><EFBFBD><EFBFBD>gameEscape<70><65><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public async Task gameEscape(string token)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ
|
|||
|
string Authorization = token;
|
|||
|
Debug.Log("Loding(Authorization)<29><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ" + Authorization);
|
|||
|
|
|||
|
// 5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ
|
|||
|
Dictionary<string, string> head51 = new Dictionary<string, string>
|
|||
|
{
|
|||
|
{ "Authorization", Authorization }, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩͷ
|
|||
|
};
|
|||
|
|
|||
|
string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
|
|||
|
Debug.Log("5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ(<28><><EFBFBD><EFBFBD>)" + response51); // <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>飺
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD>
|
|||
|
string json = response51;
|
|||
|
Response response = JsonConvert.DeserializeObject<Response>(json);
|
|||
|
|
|||
|
if (response != null && response.code == 200 && response.data != null)
|
|||
|
{
|
|||
|
gameEscapeId = response.data.gameEscapeModel.id;
|
|||
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>idΪ: " + gameEscapeId);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("<22><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class GameEscapeModel
|
|||
|
{
|
|||
|
public int id; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷID
|
|||
|
public string gameNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class GameEscapeRoomResponseVo
|
|||
|
{
|
|||
|
public int escapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>ID
|
|||
|
public int roomNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class Data
|
|||
|
{
|
|||
|
public int carrySeconds; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public GameEscapeModel gameEscapeModel; // Ƕ<><EFBFBD>GameEscapeModel<65><6C><EFBFBD><EFBFBD>
|
|||
|
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>б<EFBFBD>
|
|||
|
public object gameEscapeUserModel; // <20>û<EFBFBD>ģ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>Ϊ<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class Response
|
|||
|
{
|
|||
|
public int code; // ״̬<D7B4><CCAC>
|
|||
|
public string message; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
public Data data; // <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
|||
|
}
|
|||
|
}*/
|
|||
|
|
|||
|
|