Hello Guest

Author Topic: Advice to Begin Packing 1x/2x tk2dSpriteCollections into AssetBundles  (Read 3079 times)

aikitect

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Hello, I am interested in packing 1x/2x tk2dSpriteCollections into AssetBundles.  I started reading some of the other threads on the topic, but am not entirely clear on what actually needs to be in the AssetBundle.

Here's my best guess - please correct me where I am wrong:

1. In a new project, create a tk2dSpriteCollection that uses "1x" platform setting.  Create a different tk2dSpriteCollection that uses "2x" platform setting.  Add all the appropriate sprites and commit the collection.  Is it okay to use PNG settings here?
2. Add the tk2dSpriteCollectionData component to the AssetBundle using the following code:

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

3. Download the Asset Bundle and perform the following code for to set a sprite.

Code: [Select]
AssetBundle ab = <reference to an assetbundle>;
sprite = GetComponent<tk2dSprite>();
sprite.collection = ab.Load ("human", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
sprite.SetSprite("mySpriteName");

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Yes this is more or less correct if you want to manage it yourself.