We currently have a system where assets are loaded via ResourceController.INSTANCE.Load(assetName). There is a FileSystemResourceController, an AssetBundleResourceLoader and a UnityResourceLoader (derived from ResourceController)
These handle editor , standalone , web(scorm) asset loading differently.
We are moving towards having all our lesson specific assets in their own bundles which means calls like ResourceController.INSTANCE.Load(“level1config.xml”) need to “wait” until the bundle that contains the asset is downloaded (in web player case). The code immediately following needs to have that file loaded to continue. Has anyone else solved something similar? (ie an AssetLoader whose purpose it is to return assets from bundles …that might need to wait for bundles to be downloaded before proceeding?)
thanks,
–matt
Kinda late reply, and I’m not sure what you’re asking, but I do a lot of work with bundles and yours seems like a pretty straight-forward question. If I’m right, this should have helped ya if posted early enough:
Usage
static public IEnumerator CoDownload () {
FileHandler fileHandler = new FileHandler();
IEnumerator e = fileHandler.Download("http://www.example.com/index.html");
while ( e.MoveNext() )
yield return e.Current;
if ( fileHandler.DownloadOk() )
fileHandler.Save("somewhere/somefile.html");
else
Debug.LogError("error on download: " + fileHandler.www.error);
}
FileHandler.cs
using System.IO;
using UnityEngine;
using System.Collections;
///
/// File handler, wait for file download and do the saving process.
///
public class FileHandler {
public WWW www { get; protected internal set; }
public IEnumerator Download (string url) {
www = new WWW(url); // initiate download
yield return www;
}
public bool Save (string into) {
bool savedOk = false;
if (www != null && www.isDone && www.error == null) {
FileStream stream = null;
try {
stream = new FileStream(
into
, FileMode.Create);
} catch (System.SystemException exception) {
Debug.LogError("[FileHandler] FileStream error, which should never happen: "+ exception.Message);
}
if (stream != null) {
stream.Write(www.bytes, 0, www.bytes.Length);
stream.Close();
savedOk = true;
} else {
Debug.LogError("[FileHandler] Couldn't write to file because stream is null: "+ into);
if (www == null || www.error == null) {
Debug.LogWarning("[FileHandler] www or error is null - *most likely* the file to download was changed and this is not being loaded any more: "+ into);
} else {
Debug.LogError("[FileHandler] Couldn't save file!! "+ into +" error: "+ www.error +" error length? "+ www.error.Length);
}
}
}
Dispose();
return savedOk;
}
public void Dispose () {
www.Dispose();
www = null;
}
public bool DownloadOk () {
if (www == null) {
return false;
} else if (www.error != null) {
return false;
}
return true;
}
}