显示UnityWebRequest的进度

显示UnityWebRequest的进度

本文介绍了显示UnityWebRequest的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Unity Web请求并显示进度,根据我需要捕获的文档一个WebRequestAsyncOperation对象来查找进度,但是我找不到它

I'm trying to download an assetbundle using Unity Web Request and show the progress, according to the documentation i need to capture a WebRequestAsyncOperation object to find the progress but i cannot find it

我尝试使用AsyncOperation和UnityWebRequestAsyncOperation,并且我的例程可以同时使用,使用一个或另一个有什么区别?

I tried using AsyncOperation and UnityWebRequestAsyncOperation and my routine works with both, what is the difference of using one or another?

这是我的代码:

IEnumerator DownloadModel3D()
    {
        using (UnityWebRequest uwr = UnityWebRequest.GetAssetBundle(bundleURL,1,0))
        {
            //UnityWebRequestAsyncOperation request = uwr.SendWebRequest();
            AsyncOperation request = uwr.SendWebRequest();

            while (!request.isDone)
            {
                Debug.Log(request.progress);
                yield return null;
            }


            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
            }
            else
            {
                // Get downloaded asset bundle
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);

                assetBundleInstance = Instantiate(bundle.LoadAsset(assetName)) as GameObject;
                assetBundleInstance.transform.position = transform.position;
                assetBundleInstance.transform.localScale = new Vector3(.08f, .08f, .08f);
                assetBundleInstance.transform.SetParent(transform);
                contador.text = "Descargado: " + assetName + "\n" + bundleURL;
            }
        }
    }

推荐答案

如果您的意思是 WebRequestAsyncOperation UnityWebRequestAsyncOperation 不同,那么事实就是如此.

If you mean that WebRequestAsyncOperation is not the same as UnityWebRequestAsyncOperation, turns out they are.

UnityWebRequestAsyncOperation

UnityWebRequest .SendWebRequest()返回的异步操作对象."

"Asynchronous operation object returned from UnityWebRequest.SendWebRequest()."

您已经在使用哪种方法.

Which is the method you already are using.

来源: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAsyncOperation .html

UnityWebRequestAsyncOperation继承自AsyncOperation,这意味着它们共享相同的字段,并且可能也共享相同的方法.尽管如此,UnityWebRequestAsyncOperation仍具有以下字段:

UnityWebRequestAsyncOperation inherits from AsyncOperation, meaning they share the same fields and likely also same methods. UnityWebRequestAsyncOperation additionally has the field below though:

webRequest返回创建操作的关联UnityWebRequest.

webRequest Returns the associated UnityWebRequest that created the operation.

如果这不能回答您的问题,请详细说明.

If this didn't answer your question please elaborate.

这篇关于显示UnityWebRequest的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:45