2D Toolkit Forum

2D Toolkit => Support => Topic started by: Rif on September 11, 2014, 10:51:14 am

Title: Saving tk2dSpriteAnimation Prefab
Post by: Rif on September 11, 2014, 10:51:14 am
The game I currently has about 100 characters. So importing all the character atlas and animation with the game app wouldn't be a good approach (making the download way too big).

So what should I be doing if I want to including the character animation in separate download process.

Currently I can export the character's tk2dSpriteAnimation as .unity3d file, download them, and change the library of tk2dSpriteAnimator of character animation
Code: [Select]
IEnumerator DownloadPrefab(string url)
{
WWW downloadedFile = new WWW(url);
yield return downloadedFile;

if (downloadedFile.isDone)
{
AssetBundle assetBundle = downloadedFile.assetBundle;

spriteAnimation = assetBundle.Load("BattleAnim-CharacterA", typeof(tk2dSpriteAnimation)) as tk2dSpriteAnimation;
}
else
{
print("downloadedFile is null");
}
}
characterSpriteAnimator.Library = spriteAnimation;

But this way will make the user download a lot of characters every time they want to initiate a battle (The battle consists of 7 characters vs 7 characters, so if every sprite animation library size is 1.5 MB on average, that will be 21MB to download for just 1 battle).

Is there a way to save the tk2dSpriteAnimation I downloaded into prefab in the deployed app, so that I do not need to download the sprite animation everytime the user initiate the battle?
Title: Re: Saving tk2dSpriteAnimation Prefab
Post by: unikronsoftware on September 13, 2014, 12:25:52 pm
you cant save the prefab, but you'd save the assetbundle. You can then load it using a file:/// uri. Or you could try WWW.LoadFromCacheOrDownload or similar API functions.
Title: Re: Saving tk2dSpriteAnimation Prefab
Post by: Rif on September 15, 2014, 04:20:03 am
Thanks for the reply.
It seems my question is more of Unity general question rather than a tk2d related.

But is my way of approach correct in this? i.e. Exporting the tk2dSpriteAnimation as a single .unity3d asset bundle ? (With dependency tracking)
Title: Re: Saving tk2dSpriteAnimation Prefab
Post by: unikronsoftware on September 15, 2014, 11:42:42 am
That will work, but only if you dont use platform collections. Platform collections rely on Resources.Load which dependency tracking wont track.