x


Pausing Until AssetBundle Downloads

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

more ▼

asked May 01 '12 at 05:12 PM

dryheat70 gravatar image

dryheat70
1 4 5 7

do you mind posting your code for your derived class so that we can determine a good place to pause at?

May 01 '12 at 07:00 PM dannyskim
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

found a good link to a page explaining walking through an IEnumerable yourself Unity3D coroutines in detail

that I thought might help, but haven't had much luck... still loops through with WWW.isDone = false and no error in WWW.error.

but, wasn't able to get it to effectively block until download was complete with the following code...

    public WWW RequestAndWaitForLoad (string url)
    {     
    isLoadingBundle = true;
    Debug.Log(String.Format("##WWW requesting {0}", url));     


    int test = 0;
    IEnumerator e = FinishDownload(url);
    while(e.MoveNext()) 
    { 
       Debug.Log(String.Format("##count:{0}", test++));
    }   

    Debug.Log(String.Format("##RequestAndWaitForLoad after startcorouting "));     
    Debug.Log(String.Format("##isLoadingBundle is {0}", isLoadingBundle));     
    Debug.Log(String.Format("##wwwResults is {0} null", wwwResults == null ? "" : "NOT"));
    return wwwResults;     
}


protected IEnumerator FinishDownload(string url)
{
    WWW theWWW = new WWW(url);     
    if(theWWW.error != null)
    {
       Debug.Log(String.Format("##FinishDownload breaking with error : {0}", theWWW.error));
       yield break;            
    }
    yield return theWWW;     

    Debug.Log(String.Format("##FinishDownload Ater first yield isDone is  : {0}", theWWW.isDone));
    if(theWWW.error != null)     
    {
       Debug.Log(String.Format("##FinishDownload Ater first yield isDone is  : {0}", theWWW.isDone));              
    }

    wwwResults = theWWW;
    yield break;     
}
more ▼

answered May 02 '12 at 09:46 PM

dryheat70 gravatar image

dryheat70
1 4 5 7

(comments are locked)
10|3000 characters needed characters left

I'm afraid that would be a lot of code. The key hangup, however, is that we have code throughout similar to

levelConfigXML =  ResourceController.INSTANCE.Load("level1config.xml");
// parse levelConfigXML and assume it's already been loaded

// Below is pseudo code

class AssetBundleResourceLoader : IResourceController
{
   WWW bundleLoader; 
   String CurrBundleName;
   Object Load(string path)
   {
      String bundleName  = GetBundleFromPath(path);
      if(bundleName != CurrBundleName)
      {
         bundleLoader = RequestController.RequestAndWaitForLoad(CurrBundleName);
      }
      Object result = null;
      if(bundleLoader != null && bundleLoader.error == null && bundleLoader.isDone)
      {
          if(bundleLoader.assetBundle != null)
          {
              result = bundleLoader.assetBundle.Load(path);
          }
       }
       if(result == null)
       {
          // fallback to "parent" loader
          result = base.Load(path);
       }
    return result;
  }

  class WWWRequestController
  {  
     WWW RequestAndWaitForLoad(string url)
     {
        // have made many attempts here to essentially start a d/l of bundle and "wait" for it to complete. How have others solved this?
     }
   }

{

}

more ▼

answered May 02 '12 at 04:46 PM

dryheat70 gravatar image

dryheat70
1 4 5 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x525
x382

asked: May 01 '12 at 05:12 PM

Seen: 489 times

Last Updated: May 02 '12 at 09:46 PM