0

I have 340 sprites and I want to show them like a comic book. The comic book has 39 chapters and each chapter has around 6-10 pictures.

I noticed that Unity does not allow to loading resources from Resources folder if the file resources.assets is bigger than 2Gb, so I split all resources in two sets: first set of images are left in Resources folder, and the second set is combined into AssetBundle.

So now if I want to watch the first chapter it loads pictures from the first chapter, and if I go ahead and select the second chapter, it unloads images from the first chapter and loads images from the second chapter. But if I want to see the first chapter again then there are two situations.

If images from first chapter were loading from Resources folder - all right, it just loads them again.

If images were loading from AssetBundle - it can't just load these images again because when I was switching from first chapter to second, it unloaded resources from first chapter and they have been deleted now.

So how do I fix the second situation with AssetBundle and deleted resources? I just can't hold all unused resources in memorythe whole time.

user2686299
  • 427
  • 8
  • 25
  • why you don;t use all with asset bundles? – Muhammad Faizan Khan Dec 07 '15 at 05:39
  • because asset bundles is loading some time, and if user runs app and clicks Play button instantly it tries to show pictures but the pictures does not loaded still. User can select 4 different chapters to start from them, so pictures for these 4 chapters are in Resources folder. And while user watches pictures from these chapters, it loads asset bundle. – user2686299 Dec 07 '15 at 09:39

1 Answers1

1

Just load the asset bundle again using the WWW class exactly as you did before. You will have to let your app wait until the loading is done. You should show a loading popup while it is loading.

Something like this in a coroutine:

WWW www = WWW.LoadFromCacheOrDownload (url, 1);
yield return www;
AssetBundle bundle = www.assetBundle;
AssetBundleRequest request = bundle.LoadAssetAsync ("img1", typeof(Texture2D));
yield return request;
Texture2D img = request.asset as Texture2D ;

http://docs.unity3d.com/Manual/LoadingAssetBundles.html

Denis L.
  • 86
  • 4
  • but whether it is expedient in terms of performance? What you think about next approach: just move all images into StreamingAssets folder and load them through WWW class? – user2686299 Dec 07 '15 at 11:24
  • @user2686299: you are right this would be even better! This way every picture could be loaded when it is needed and there is no overhead of loading a huge bundle where only a few images are really used. Also loading a png is faster than loading a bundle+decompressing it and loading the png from there. – Denis L. Dec 08 '15 at 08:46