@unikron, @Pani
Attach this script to a game object and it works nicely!
I don't know if this is the best way to do it though?
using UnityEngine;
using System.Collections;
using System.IO;
public class TexturePackerCollection : MonoBehaviour {
Texture2D theTexture; // For the texture
string theData; // For Texture Packer 2d Toolkit .bytes file
FileStream theStream; // For loading image
byte[] theImageData; // Array for image data
tk2dRuntime.SpriteCollectionSize theSize; // Collection size
tk2dSpriteCollectionData theCollection; // For the created collection
void Start () {
// Get size using 2d Toolkit camera
theSize = tk2dRuntime.SpriteCollectionSize.ForTk2dCamera();
// *** OR ***
// Get size for orthographic camera float orthoSize, float targetHeight
//theSize = tk2dRuntime.SpriteCollectionSize.Explicit(100f, 320f);
// Create the texture
theTexture = new Texture2D(512, 512);
// Read Texture Packer data file into string
theData = File.ReadAllText("atlas.bytes");
// Read the image file into the texture
theStream = new FileStream("atlas.png", FileMode.Open, FileAccess.Read);
theImageData = new byte[theStream.Length];
theStream.Read(theImageData, 0, (int) theStream.Length);
theTexture.LoadImage(theImageData);
// Create the collection
tk2dSpriteCollectionData theCollection = tk2dSpriteCollectionData.CreateFromTexturePacker(theSize, theData, theTexture);
// Add the named sprite to the game object that this script is attatched to
tk2dSprite.AddComponent(gameObject, theCollection, "progressBar");
}
}
cheers
evs