void Update()
{
// Collect all the finished WWWs.
var keysToRemove = new List<string>();
foreach (var keyValue in m_DownloadingWWWs)
{
WWW download = keyValue.Value;
// If downloading fails.
if (download.error != null)
{
m_DownloadingErrors.Add(keyValue.Key, string.Format("Failed downloading bundle {0} from {1}: {2}", keyValue.Key, download.url, download.error));
keysToRemove.Add(keyValue.Key);
continue;
}
// If downloading succeeds.
if(download.isDone)
{
AssetBundle bundle = download.assetBundle;
if (bundle == null)
{
m_DownloadingErrors.Add(keyValue.Key, string.Format("{0} is not a valid asset bundle.", keyValue.Key));
keysToRemove.Add(keyValue.Key);
continue;
}
//Debug.Log("Downloading " + keyValue.Key + " is done at frame " + Time.frameCount);
m_LoadedAssetBundles.Add(keyValue.Key, new LoadedAssetBundle(download.assetBundle) );
keysToRemove.Add(keyValue.Key);
}
}
// Remove the finished WWWs.
foreach( var key in keysToRemove)
{
WWW download = m_DownloadingWWWs[key];
m_DownloadingWWWs.Remove(key);
download.Dispose();
}
// Update all in progress operations
for (int i=0;i<m_InProgressOperations.Count;)
{
if (!m_InProgressOperations[i].Update())
{
m_InProgressOperations.RemoveAt(i);
}
else
i++;
}
}