From 0bb467fafccfa6fb0e5922d3095848e34d9b6544 Mon Sep 17 00:00:00 2001 From: iMobCoding - Laptop Date: Sun, 26 Oct 2025 19:57:38 +0100 Subject: [PATCH] Fix Google translator obsolete code --- .../Runtime/Utilities/GoogleTranslator.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Packages/com.gametoolkit.localization/Runtime/Utilities/GoogleTranslator.cs b/Packages/com.gametoolkit.localization/Runtime/Utilities/GoogleTranslator.cs index 40942e0..806ad02 100644 --- a/Packages/com.gametoolkit.localization/Runtime/Utilities/GoogleTranslator.cs +++ b/Packages/com.gametoolkit.localization/Runtime/Utilities/GoogleTranslator.cs @@ -1,6 +1,5 @@ // Copyright (c) H. Ibrahim Penekli. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. - using System; using System.Collections; using UnityEngine; @@ -99,7 +98,15 @@ private void ProcessResponse(GoogleTranslateRequest request, UnityWebRequest www Action onCompleted, Action onError) { - if (www.isNetworkError || www.isHttpError) + var hasError = false; +#if UNITY_2020_2_OR_NEWER + var requestResult = www.result; + hasError = requestResult != UnityWebRequest.Result.Success; +#else + hasError = www.isNetworkError || www.isHttpError; +#endif + + if (hasError) { if (onError != null) { @@ -112,11 +119,11 @@ private void ProcessResponse(GoogleTranslateRequest request, UnityWebRequest www if (response != null && response.data != null && response.data.translations != null && response.data.translations.Length > 0) { - var requests = new GoogleTranslateRequest[] {request}; + var requests = new GoogleTranslateRequest[] { request }; var translateResponse = new GoogleTranslateResponse(); translateResponse.TranslatedText = response.data.translations[0].translatedText; - var responses = new GoogleTranslateResponse[] {translateResponse}; + var responses = new GoogleTranslateResponse[] { translateResponse }; if (onCompleted != null) { @@ -152,7 +159,7 @@ private class JsonData { public JsonTranslation[] translations = null; } - + [Serializable] private class JsonError { @@ -202,7 +209,7 @@ public class TranslationErrorEventArgs : EventArgs /// Error code. /// public long ResponseCode { get; private set; } - + /// /// Error message. ///