[英]'UnityWebRequest' does not contain a definition for 'result'
When I use the code satable for the unity 2021 in the unity 2019.当我在 unity 2019 中使用代码 satable for unity 2021 时。
The console shows that控制台显示
'UnityWebRequest' does not contain a definition for 'result' and no accessible extension method 'result' accepting a first argument of type 'UnityWebRequest' could be found (are you missing a using directive or an assembly reference?)
“UnityWebRequest”不包含“result”的定义,并且找不到接受“UnityWebRequest”类型的第一个参数的可访问扩展方法“result”(您是否缺少 using 指令或程序集引用?)
Bugs/problem:错误/问题:
if (req.result == UnityWebRequest.Result.ConnectionError || req.result == UnityWebRequest.Result.ProtocolError)
I expect I can use those code on unity 2019 with other codes and works.我希望我可以在 unity 2019 上将这些代码与其他代码和作品一起使用。
Simply consult the API!只需查阅 API!
result
was added in version 2020.3. result
在版本 2020.3 中添加。
Prior to that version simply follow the examples from the according version API eg 2019.4 API在该版本之前,只需遵循相应版本 API 中的示例,例如2019.4 API
You can eg simply check if there is any content in error
您可以例如简单地检查是否有任何内容
error
using (var webRequest = UnityWebRequest.Get(uri))
{
yield return webRequest.SendWebRequest();
if (!string.IsNullOrWhiteSpace(webRequest.error))
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}
Debug.Log(webRequest.downloadHandler.text);
}
or if you want to further differentiate isNetworkError
(includes errors like no internet connection, host not reachable, DNS resolve error etc) and isHttpError
(basically same as responseCode >= 400
)或者,如果您想进一步区分
isNetworkError
(包括无互联网连接、主机不可访问、DNS 解析错误等错误)和isHttpError
(与responseCode >= 400
基本相同)
If your question is about downwards compatibility but support both versions either stick to the pre-2020.3 way or use Conditional Compilation and do eg如果您的问题是关于向下兼容性但同时支持这两个版本,要么坚持 2020.3 之前的方式,要么使用条件编译,例如
#if UNITY_2020_3_OR_NEWER
if(webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError)
#else
if(!string.IsNullOrWhiteSpace(webRequest.error))
#endif
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.