1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| using System;
| using Cysharp.Threading.Tasks;
| using UnityEngine;
| using UnityEngine.Networking;
|
|
| public class HttpRequestEx
| {
|
|
| //回合战报
| public static void UnityWebRequestTurnFightGet(string _url, string guid, int mapID, int timeout = 5, Action<bool, string, int, byte[]> _result = null)
| {
| GetTurnFightData(_url, guid, mapID, timeout, _result).Forget();
| }
|
| static async UniTask GetTurnFightData(string remoteURL, string guid, int mapID, int timeout, Action<bool, string,int, byte[]> _result = null)
| {
| try
| {
| UnityWebRequest request = UnityWebRequest.Get(remoteURL);
| request.timeout = timeout;
| await request.SendWebRequest();
| if (request.isDone)
| {
| if (request.result == UnityWebRequest.Result.Success)
| {
| _result(true, guid, mapID, request.downloadHandler.data);
| }
| else
| {
| Debug.LogError("GetDataBEx 失败 " + request.result.ToString());
| _result(false, guid, mapID, null);
| }
| }
| }
| catch (Exception ex)
| {
| _result(false, guid, mapID, null);
| Debug.LogError($"GetDataBEx 异常 - URL: {remoteURL}, Exception: {ex.Message}");
| }
|
| }
|
|
| }
|
|