From 9dd23092f528054d77e65112ac06fe9d98f8bca7 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 5 May 2020 16:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86UnityWebRequest=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Utility/XChartsMgr.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Runtime/Utility/XChartsMgr.cs b/Runtime/Utility/XChartsMgr.cs index 9f95d7ea..896ccb5f 100644 --- a/Runtime/Utility/XChartsMgr.cs +++ b/Runtime/Utility/XChartsMgr.cs @@ -107,7 +107,7 @@ namespace XCharts var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/version.json"; var web = UnityWebRequest.Get(url); yield return web; - if (web.isNetworkError) + if (IsNetworkError(web)) { isNetworkError = true; networkError = web.error; @@ -144,7 +144,7 @@ namespace XCharts var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/CHANGELOG.md"; var web = new UnityWebRequest(url); yield return web; - if (!web.isNetworkError) + if (IsNetworkError(web)) { Debug.LogError(web.error); } @@ -192,5 +192,29 @@ namespace XCharts } changeLog = sb.ToString(); } + +#if UNITY_5 || UNITY_2017_1 + public bool IsNetworkError(UnityWebRequest request) + { + return request.isError && !IsHttpError(request); + } +#else + public bool IsNetworkError(UnityWebRequest request) + { + return request.isNetworkError; + } +#endif + +#if UNITY_5 + public bool IsHttpError(UnityWebRequest request) + { + return request.responseCode >= 400; + } +#else + public bool IsHttpError(UnityWebRequest request) + { + return request.isHttpError; + } +#endif } } \ No newline at end of file