显示 UnityWebRequest 的进度

Show Progress of UnityWebRequest

我正在尝试使用 Unity Web Request and show the progress, according to the documentation 下载 assetbundle 我需要捕获 WebRequestAsyncOperation 对象来查找进度但我找不到它

我尝试使用 AsyncOperation 和 UnityWebRequestAsyncOperation,我的例程适用于两者,使用一个或另一个有什么区别?

这是我的代码:

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

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

如果你的意思是 WebRequestAsyncOperationUnityWebRequestAsyncOperation 不同,结果证明它们是。


UnityWebRequestAsyncOperation

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

这是您已经在使用的方法。

来源: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 继承自 AsyncOperation,这意味着它们共享相同的字段并且可能还共享相同的方法。 UnityWebRequestAsyncOperation 另外还有以下字段:

webRequest Returns 创建操作的关联 UnityWebRequest。

如果这没有回答您的问题,请详细说明。