Hello Guest

Author Topic: Sprite Collection and AssetBundle  (Read 14661 times)

mattsmee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Sprite Collection and AssetBundle
« on: April 28, 2012, 05:29:25 am »
Here my situation:
The game I'm working on support dynamic content download from our server. We put everything in AssetBundle (not Unity Package) then game would download it using WWW and use the content of that AssetBundle.

Question is, how do I put the Sprite Collection in an AssetBundle, and later be able to use the sprite collection programmatically like this:

AssetBundle ab = <reference to an assetbundle>;
sprite = GetComponent<tk2dSprite>();
sprite.collection = ab.Load ("human", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;

Thanks in advance!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #1 on: April 28, 2012, 09:06:35 am »
Thats a good question.

The way to do this, is to simply add the "data" object containing the "tk2dSpriteCollectionData" component to the AssetBundle. That object has explicit dependencies to everything that is necessary, and as such should be sufficient for you to do what you've described.

Note: You should NOT put the "tk2dSpriteCollection" object which you edit into the sprite collection.

mattsmee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #2 on: April 28, 2012, 08:08:47 pm »
Thanks for the great support!

I've created ItemThumbs (a tk2dSpriteCollection) which it created a folder ItemThumbs_Data. Within ItemThumbs_Data there's the tk2dSpriteCollectionData with default name "data". This tk2dSpriteCollectionData is only 28KB while in this spritecollection I have 55 images. Did you say I only need this tk2dSpriteCollectionData and nothing else? I guess I'd need the atlas images as well?

The problem I have is, AssetBundle does not support directories (everything is flattened). I'm forced to put everything side by side. Would this break the dependencies stored in that "data" object?

Thanks again!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #3 on: April 28, 2012, 08:24:44 pm »
While the data object is tiny, it will pull automatically pull in the textures and materials. You don't / shouldn't have to add the material and texture explicitly. You are free to rename the data object to anything you like, if that suits you better.

mattsmee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #4 on: April 28, 2012, 09:17:33 pm »
Thanks for the reply, unikron!

I'm not getting it.. Let's say you downloaded my game. 10 days later I decided to create new items as an assetbundle on my Mac and send it to the server. The game on your phone will download the assetbundle which contains the data file. How can your phone see the images if I just put the data file in assetbundle without any images (atlas)?

Some explanation would be much appreciated! Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #5 on: April 29, 2012, 12:35:29 am »
Hi Matt,
When you create an asset bundle using something like this:

Code: [Select]
tk2dSpriteCollectionData data;
BuildPipeline.BuildAssetBundle(data, new Object[] { data }, path, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies);

The dependencies will automatically be collected. The texture & material are dependencies of the sprite collection and as such, will automatically be included in the asset bundle without you explicitly telling it to.

Asset bundle compression is really really good - I had a sprite collection with an 1024x512 atlas compress down to 32k.

mattsmee

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sprite Collection and AssetBundle
« Reply #6 on: April 29, 2012, 01:14:25 am »
Thanks, Unikron

Glad to know it's possible :) I'd have to rewrite the AssetBundle editor script and give it a try. Thank a lot!