Search Unity

Building and retrieving AssetBundles from URL in Unity 5

Discussion in 'Scripting' started by sudhaMR, Jun 30, 2015.

  1. sudhaMR

    sudhaMR

    Joined:
    Jun 17, 2015
    Posts:
    12
    My code loops through a for loop and retrieves URL for images in every loop. I display all these as a Grid Layout in my Panel in the UI Canvas. There are over 300 images and it takes a lot of time to load each using
    Code (JavaScript):
    1. var www: WWW = new WWW(url);    
    So, now I want to build a cache of these images initially while loading the application using
    Code (JavaScript):
    1. var www: WWW =  WWW.LoadFromCacheOrDownload(url,1);
    1. But, I am not really sure how to use the AssetBundles. I saw the 5.x docs and I don't understand where the
    Code (JavaScript):
    1.  BuildPipeline.BuildAssetBundles ("AssetBundles");
    points to.

    2. I have a scene which has the UI Panel where I Instantiate buttons using script in a Grid layout. The images on these buttons are the images to be loaded from the URL. There is nothing in the Asset folder from my hard disk for this scene except the script generating the images. Which part of it should I make into an AssetBundle?

    3. What is this 2nd DropDown menu near the Asset bundle name (Image attached)?
    Capture asset bundle.PNG

    4. And finally, where should I attach the scripts required? I read that in 4.x versions they should be put in a "Editor" folder. What is the script that would help me load and cache these images?

    5.Solve the "WWWCached data can only be accessed using the assetBundle property!
    UnityEngine.WWW:get_text()" error.

    Code (JavaScript):
    1. var yyy: WWW = new WWW(imgurl,1);
    2.         yield yyy;
    3.         var bundle:AssetBundle = yyy.assetBundle;
    4.         var imageUrl: JsonData = JsonMapper.ToObject(yyy.text);
    5.      
    6.         var temp: String = imageUrl["query"]["pages"][PageID]["thumbnail"]["source"].ToString();
    7.         Debug.Log("Image URL:"+temp);
    8.      
    9.         var zzz: WWW = WWW.LoadFromCacheOrDownload(temp);          
    10.         yield zzz;
    11.         Debug.Log ("Loaded Image");      
    12.  
    13.         var texture: Texture2D = zzz.texture;
    14. var img: UnityEngine.UI.Image  = button.gameObject.GetComponent(UnityEngine.UI.Image);
    15. img.sprite = Sprite.Create (texture, new Rect (0, 0, texture.width , texture.height),Vector2.zero);
    16.  
    Note: One of the URLs : https://en.wikipedia.org/w/api.php?...p=original&iwurl=&rawcontinue=&titles=Swallow
    and Image URL: https://upload.wikimedia.org/wikipedia/commons/0/0f/Red-rumpedSwallow01.jpg
     

    Attached Files:

  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Thank @Will Goldstone for taking down the Unity5 asset bundling training.

    The scripts don't get attached. They are editor scripts that help you "build them"

    Check out: http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html

    I believe the content developers of unity are working on another asset bundle tutorial. There seem to be issues with the last one. Hence why it was taken down.

    Also, this discussion is pretty useful. It'll answer some questions you have:

     
  3. pauwau

    pauwau

    Joined:
    Jun 12, 2015
    Posts:
    2
    couldn't get all out of the two links provided by subzerogaming mentioned above
    additionally I found the demo.zip in
    http://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/
    quiet useful - it will answer most of your questions by example code.
    (3. - answer you will find among 'Variants')
    but...also the unmodified examples work for me in the Editor
    - I have a big problem (maybe only on my platforms win x86 and x64 never mentioned elsewhere) when changing assetbundles by adding content.
    the building process seams to be ok (by examening the manifest files),
    but Load() resp. LoadLevel() in neither of the 3 examples succeeds to render additional content.
    I always get the predefined cube in render output.
    Maybe I should place that issue in a seperate thread,
    but in case you verify - give me a short note about your experiences please
     
    Last edited: Jul 2, 2015