在单个进度条中下载多个unity3d assetsbundle?

时间:2017-09-02 17:02:18

标签: c# unity3d progress-bar assetbundle

我正在尝试为多个assetbundle创建一个下载进度条。所有assetbundle的总大小是通过添加webRequest.GetResponseHeader("Content-Length")来计算的。但www.downloadProgress仅返回0到1之间的值。

以下是示例代码:

float progress = 0;

for (int i = 0; i < assetToDownload.Count; i++)
{
    UnityWebRequest www = UnityWebRequest.GetAssetBundle(assetToDownload[i], 0, 0);
    www.Send();

    while (!www.isDone)
    {
        progress += www.downloadProgress * 100;
        Debug.Log((progress / totalSize) * 100);
        yield return null;

    }
}

1 个答案:

答案 0 :(得分:1)

不要通过使用不同的请求获取内容大小来使自己如此努力。您只需要使用统一的0-1值并将它们加在一起。当从进度条中查看它时,这不会产生差异,并且在实施中不会产生这样的痛苦。 我希望这会有所帮助。

//To calculate the percantage
float maxProgress = assetToDownload.Count;

for (int i = 0; i < assetToDownload.Count; i++)
{
    UnityWebRequest www = UnityWebRequest.GetAssetBundle(assetToDownload[i], 0, 0);
    www.Send();

    //To remember the last progress
    float lastProgress = progress;
    while (!www.isDone)
    {
        //Calculate the current progress
        progress = lastProgress + www.downloadProgress;
        //Get a percentage
        float progressPercentage = (progress / maxProgress) * 100;
    }
}