Hello,
I am testing Asset Bundles on WebGL for a future project and I am trying to make a loading bar while an asset bundle is downloaded from a remote server. In Editor everything works fine, but when I run the project from a remote server the progress stays at 0 until the download is complete.
This is the code I am using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class LoadScene : MonoBehaviour {
[SerializeField]
LoadingBar loadingBar;
AsyncOperation downloadOperation;
void Start () {
StartCoroutine (LoadGameScene ());
}
bool FinishedLoadingTextures(){
Debug.Log (downloadOperation.progress);
loadingBar.SetProgress (downloadOperation.progress);
return downloadOperation.isDone;
}
IEnumerator LoadGameScene(){
Debug.Log ("Started textures");
string texturesPath = "[texture_bundle_url]";
UnityWebRequest request = UnityWebRequest.GetAssetBundle (texturesPath,0);
downloadOperation = request.Send ();
yield return new WaitUntil(FinishedLoadingTextures);
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
yield return bundle.LoadAllAssetsAsync ();
Debug.Log ("finished textures, starting scene");
string scenePath = "[scene_bundle_url]";
request = UnityWebRequest.GetAssetBundle (scenePath,0);
yield return request.Send ();
bundle = DownloadHandlerAssetBundle.GetContent(request);
Debug.Log ("finished scene");
string[] scenes = bundle.GetAllScenePaths();
yield return SceneManager.LoadSceneAsync (scenes [0]);
SceneManager.UnloadSceneAsync (SceneManager.GetActiveScene ());
}
}
I’m using SRDebugger and while in Unity Editor the progress bar works just as it should, while testing it in browser the Debug.Log at line 19 just prints 0 until the bundle is downloaded. I am using Unity 5.5.0f3. Any sugestions?
EDIT: Same thing happens if I use WWW instead of UnityWebRequest.