Hello Guest

Author Topic: Sprite or AnimatedSprite from AssetBundle  (Read 5223 times)

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
Sprite or AnimatedSprite from AssetBundle
« on: August 21, 2012, 02:27:41 pm »
Hi,

I would like to put together a POC for loading an assetBundle containing multiple AnimatedSprites.

For my initial test I created one bundle containing a gameobject, that has multiple animatedsprites - this did not work, as it seemed that only the top level GameObject(prefab in source scene) got loaded.  Structure of Bundle:
AssetBundle
-> Prefab(GameObject)
--> AnimatedSprite_A
--> AnimatedSprite_B

For the second test, I created the source structure like so:
AssetBundle
-> Prefab(AnimatedSprite_A)

This second test worked, but it poses a problem as it will require loading many AssetBundles, basically one for each tk2d GameObject.

Has someone tried this before successfully. Ultimately, I would like to load one AssetBundle (Prefab) that contains pretty much ALL the assets for an entire game.

Any help or advice will be largely appreciated.

Thanks,
Yuri

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite or AnimatedSprite from AssetBundle
« Reply #1 on: August 21, 2012, 08:13:16 pm »
This is doable using your first method. When creating your asset bundle, did you set BuildAssetBundleOptions.CollectDependencies?

Alternatively, you can use:
BuildPipeline.BuildAssetBundle( AnimatedSprite_A, new Object[] { AnimatedSprite_A, AnimatedSprite_B, ... } ...);
Don't forget you'll need to add all dependencies manually if you want to do it this way.
There is one more huge advantage of doing it like this - when Unity creates an asset bundle, it will go in and make all assets unique - that means the shader within your asset bundle will be unique compared to the shader in your scene, and materials within the asset bundle will be unique as well, making it really annoying if you want to edit shaders, etc. on loaded assets. The way around this is to "repatch" the shaders correctly after loading the asset bundle in - i.e. keep a dictionary of Material - Shader, and use fix up the Material.shader = Shader.Find("...")

With this method, after creating your asset bundle, use Load("...") to load the object you want.

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Sprite or AnimatedSprite from AssetBundle
« Reply #2 on: August 22, 2012, 03:12:25 am »
Wow...got this working thanks to your help.

One more point for the awesome tk2d!