Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Q: LoadFromCacheOrDownload non asset bundles

Discussion in 'Scripting' started by ThomasVandenberghe, Apr 16, 2014.

  1. ThomasVandenberghe

    ThomasVandenberghe

    Joined:
    Feb 28, 2014
    Posts:
    22
    Hello,

    Is there any build-in way to download and cache anything other than asset bundles. I'd be using asset bundles for my layout, but I don't want to rebuild my entire bundle for the sake of editing 1 texture.

    My approach is currently an json which contains the following:

    - Path to the asset bundle containing the layout
    - Paths to the json containing all data about the asset (numbers, text, image paths)

    There would be a fair amount of asset bundles, each containing roughly 30-40 images.

    I'm using WWW.LoadFromCacheOrDownload to cache my asset bundles, but it doesn't work with textures.

    Code (csharp):
    1. using(WWW www = WWW.LoadFromCacheOrDownload(backgroundURL, version)) {
    2.     yield return www;
    3.     if (www.error != null)
    4.         throw new Exception("WWW download had an error:" + www.error);
    5.  
    6.     Texture2D t = www.texture;
    7. }
    Code (csharp):
    1. WWWCached data can only be accessed using the assetBundle property!
    2. UnityEngine.WWW:get_texture()
    Would there be a build-in way to cache it, or would I have to write the caching system myself?