hch
2 天以前 e89879d3f4e3c673c40042f41ac342cd63a0d9a6
0312 请求战报防范网络报错
1个文件已修改
2个文件已添加
69 ■■■■■ 已修改文件
Main/System/Settlement/BattleSettlementManager.cs 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Utility/HttpRequestEx.cs 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Utility/HttpRequestEx.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Settlement/BattleSettlementManager.cs
@@ -231,7 +231,7 @@
            assetVersionUrl = $"{url}/S{serverID}/{date}/{PlayerDatas.Instance.baseData.PlayerID}/{mapID}/{guid}.tfr";
        }
        Debug.Log($"请求战报: {assetVersionUrl}");
        HttpRequest.Instance.UnityWebRequestTurnFightGet(assetVersionUrl, guid, 3, OnGetTurnFightData);
        HttpRequestEx.UnityWebRequestTurnFightGet(assetVersionUrl, guid, 3, OnGetTurnFightData);
    }
    void OnGetTurnFightData(bool _ok, string guid, byte[] _result)
@@ -240,6 +240,11 @@
        {
            ReadTurnFightInfo(_result);
        }
        else
        {
            Debug.Log($"请求战报失败");
            UIManager.Instance.CloseWindow<MapLoadingWin>();
        }
    }
    //战报存储的是B430封包,所以需要转发B430封包
Main/Utility/HttpRequestEx.cs
New file
@@ -0,0 +1,51 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
public class HttpRequestEx
{
    //回合战报
    public static void UnityWebRequestTurnFightGet(string _url, string guid, int timeout = 5, Action<bool, string, byte[]> _result = null)
    {
        GetTurnFightData(_url, guid, timeout, _result).Forget();
    }
    static async UniTask GetTurnFightData(string remoteURL, string guid, int timeout, Action<bool, string, byte[]> _result = null)
    {
        UnityWebRequest request = UnityWebRequest.Get(remoteURL);
        request.timeout = timeout;
        try
        {
            await request.SendWebRequest();
            if (request.isDone)
            {
                if (request.result == UnityWebRequest.Result.Success)
                {
                    _result(true, guid, request.downloadHandler.data);
                }
                else
                {
                    Debug.LogError("GetDataBEx 失败 " + request.result.ToString());
                    _result(false, guid, null);
                }
            }
        }
        catch (Exception ex)
        {
            _result(false, guid, null);
            Debug.LogError($"GetDataBEx 异常 - URL: {remoteURL}, Exception: {ex.Message}");
        }
        finally
        {
            request.Dispose();
        }
    }
}
Main/Utility/HttpRequestEx.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed6e4a4c512e51645bbbc07aef5a50f8
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: