I have an AssetBundle download system that works fine in editor; I can download a file from a file server, a slider shows download progress and then opens the scene from the AssetBundle. However, when I build to WebGL, upload the build to my server and run it the download slider just sits at zero until the scene eventually opens.
I've been printing out www.responseHeaders and I can see that while running in editor I receive the 'content-length' header but from the server I don't. I'm guessing this is the issue, because www.progress needs the content-length to figure out the percentage downloaded. My question is: why would I not receive the content-length header when running from the server? Is there any way to force the content-length header to be sent when I make a download request?
This is my download function:
IEnumerator CoDownload()
{
List sceneNames = new List();
WWW download;
download = WWW.LoadFromCacheOrDownload(bundleUrl, 0);
bool hasLoaded = false;
string bundleName = Path.GetFileNameWithoutExtension(bundleUrl);
if (!hasLoaded)
{
using (download = WWW.LoadFromCacheOrDownload(bundleUrl, 0))
{
while (!download.isDone && string.IsNullOrEmpty(download.error))
{
progressBar.value = download.progress;
print("setting progress bar value to " + download.progress);
yield return null;
}
if (!string.IsNullOrEmpty(download.error))
{
Debug.LogError(download.error);
yield break;
}
//Print out response headers if any were received
if(download.responseHeaders != null)
{
if (download.responseHeaders.Count > 0)
{
foreach (KeyValuePair entry in download.responseHeaders)
{
Debug.Log(entry.Value + " = " + entry.Key);
}
}
}
else
{
Debug.Log("No response headers");
}
var assetBund = download.assetBundle;
if (assetBund != null)
{
sceneNames.AddRange(assetBund.GetAllScenePaths());
bool temp2 = false;
SceneManager.LoadScene(sceneNames[0]);
print("scene name is " + (Path.GetFileNameWithoutExtension(sceneNames[0])));
assetBund.Unload(false);
}
}
}
↧