Show Progress of UnityWebRequest

瘦欲@ 提交于 2019-12-11 17:07:22

问题


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

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

here is my code:

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;
            }
        }
    }

回答1:


i need to capture a WebRequestAsyncOperation object to find the progress but i cannot find it

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


UnityWebRequestAsyncOperation

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

Which is the method you already are using.

Source: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAsyncOperation.html

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

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

webRequest Returns the associated UnityWebRequest that created the operation.

If this didn't answer your question please elaborate.



来源:https://stackoverflow.com/questions/48849565/show-progress-of-unitywebrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!