In the Start of my scenes I call the method that downloads the assetBundles for that scene. The problem is that it only downloads the first assetBundle from the list, the second does not download it. My code is:
Note: The Debug that shows the url shows the correct url both times, first http://mihost.com/assetbundles/asset1 and then http://mihost.com/assetbundles/asset2. However, in the Debug that shows the assets 'added' in both cases it shows the name only of those in asset1
public virtual IEnumerator LoadBundleFromServer()
{
var AssetPathOnServer = "http://mihost.com/assetbundles/"
var assetBundleNames = new List<string>();
assetBundleNames.Add("asset1");
assetBundleNames.Add("asset2");
for (int i = 0; i < assetBundleNames.Count; i++)
{
var currentAssetBundleName = assetBundleNames[i];
var url = AssetPathOnServer + currentAssetBundleName;
Debug.Log("url: " + url);
var request = UnityWebRequestAssetBundle.GetAssetBundle(url);
yield return request.SendWebRequest();
if (!request.isHttpError && !request.isNetworkError)
{
var asseBundle = DownloadHandlerAssetBundle.GetContent(request,);
Debug.Log("count assets: " + AssetNames.Count);
for (int j = 0; j < AssetNames.Count; j++)
{
string assetName = AssetNames[j];
AssetBundleRequest asset = asseBundle.LoadAssetAsync<AudioClip>(assetName);
yield return asset;
AudioClip myClip = asset.asset as AudioClip;
if (!assetDictionary.ContainsKey(assetName))
{
assetDictionary.Add(assetName, myClip);
}
Debug.Log("added: " + assetName);
}
asseBundle.Unload(false);
}
else
{
//TODO: aqui hay que mostrar un error
Debug.LogErrorFormat("error request [{0}, {1}]", url, request.error);
}
}
}
public abstract List<string> AssetNames
{
get;
}