小编Sha*_*rif的帖子

如何使用 UnityWebRequest 从服务器下载 Asset Bundle 获取下载进度?

我还是新手,使用 UnityWebRequest 从服务器容器下载和加载资产包。问题是下载进度的值始终为 0。如何获取下载进度的值?

代码下面是我尝试下载并获取下载进度的内容。

//Method to download the assetbundle
IEnumerator DownloadAsset()
{
    string url = here the URL for asset bundle;
    using (var uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET))
    {
        uwr.downloadHandler = new DownloadHandlerAssetBundle(url, 36, 0);
        UnityWebRequestAsyncOperation operation = uwr.SendWebRequest();
        yield return StartCoroutine(DownloadProgress(operation));

        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
        {
            print("Get asset from bundle...");
        }


        //Load scene
        uwr.Dispose();
        print("ready to Load scene from asset...");
        StartCoroutine(LoadSceneProgress("Example"));
        bundle.Unload(false);
    }
}

//Method for download progress
IEnumerator DownloadProgress(UnityWebRequestAsyncOperation operation)
{
    while (!operation.isDone)
    {
        progressBar.color = Color.red; …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unitywebrequest

1
推荐指数
1
解决办法
8089
查看次数

标签 统计

c# ×1

unity-game-engine ×1

unitywebrequest ×1