少年修仙传客户端基础资源
hch
2024-09-26 f44f7df16e9f510c21aadee1d9f08e29a3bb415e
0312 HttpWebRequest请求CDN资源改用UnityWebRequest
2个文件已修改
40 ■■■■■ 已修改文件
Assets/Launch/HttpRequest/HttpRequest.cs 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Launch/ResourcesModel.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Launch/HttpRequest/HttpRequest.cs
@@ -5,6 +5,7 @@
using System.Net;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
namespace StartAot
@@ -31,6 +32,33 @@
            HttpBehaviour.Create(_url, "GET", "", _contentType, _retry, _result);
        }
        //2024-09-26 HttpWebRequest Get CDN资源在某些节日可能无法访问 包含keepalive的设定等不同情况 改用UnityWebRequest
        //获取CDN资源不建议使用HttpWebRequest
        public void UnityWebRequestGet(string _url, int timeout = 5, Action<bool, string> _result = null)
        {
            StartCoroutine(GetDataB(_url, timeout, _result));
        }
        IEnumerator GetDataB(string remoteURL, int timeout, Action<bool, string> _result = null)
        {
            UnityWebRequest request = UnityWebRequest.Get(remoteURL);
            request.timeout = timeout;
            yield return request.SendWebRequest();
            if (request.isDone)
            {
                if (request.result == UnityWebRequest.Result.Success)
                {
                    _result(true, request.downloadHandler.text);
                }
                else
                {
                    _result(false, request.result.ToString());
                }
            }
        }
        static StringBuilder buffer = new StringBuilder();
        public static string HashtablaToString(IDictionary<string, string> parameters)
        {
Assets/Launch/ResourcesModel.cs
@@ -27,7 +27,10 @@
        public bool isPCTestDownLoad = false;
        public static readonly string[] VERSION_URL = new string[] {
        "http://vncenter.daojmengxvn.com:11000/center/appversion_new.php/?"};
        "http://vncenter.daojmengxvn.com:11000/center/appversion_new.php/?",
        "http://8.218.91.247:11000/center/appversion_new.php/?",
        "https://vncenter.daojmengxvn.com:11001/center/appversion_new.php/?",
        "https://8.218.91.247:11001/center/appversion_new.php/?"};
        readonly static List<string> excludePngs = new List<string>() { "Launch_1.png", "Launch_2.png", "Launch_3.png", "LoginBackGround.png", "TB_DL_Logo.png" };
@@ -190,8 +193,8 @@
            tables["game"] = versionConfig.gameId;
            //var url = string.Concat(VERSION_URL[urlIndex % 2], HttpRequest.HashtablaToString(tables));
            var url = string.Concat(VERSION_URL[0], HttpRequest.HashtablaToString(tables));
            var url = string.Concat(VERSION_URL[urlIndex % VERSION_URL.Length], HttpRequest.HashtablaToString(tables));
            urlIndex++;
            versionUrl = url;
            Debug.Log("http地址:versionUrl  " + url);
@@ -367,7 +370,8 @@
            //var localURL = string.Concat(.ExternalStorePath, "/logicbytes.txt");
            assetBytesUrl = remoteURL;
            Debug.Log("http地址:logicbytesUrl  " + assetBytesUrl);
            HttpRequest.Instance.RequestHttpGet(assetBytesUrl, HttpRequest.defaultHttpContentType, 3, OnGetAssetVersionFile);
            //HttpRequest.Instance.RequestHttpGet(assetBytesUrl, HttpRequest.defaultHttpContentType, 3, OnGetAssetVersionFile);
            HttpRequest.Instance.UnityWebRequestGet(assetBytesUrl, 5, OnGetAssetVersionFile);
        }
        private void OnGetAssetVersionFile(bool _ok, string _result)