How would won save tk2dSpriteCollectionData to disk so that it doesn't have to be recreated at a later date? I'm guessing it wouldn't be able to be serialized and saved. I couldn't find a decent explanation and I've been fishing around the tk2d files for the past several hours for clues.
This is the code I have, it creates a sprite collection from a png file but the file save does not work because it wont let me serialize tk2dSpriteCollectionData.
using UnityEngine;
using System.Collections;
using System.IO;
using PixelShootLibrary;
public class PixelShootCreateTileSpriteCollectiona : MonoBehaviour {
string imageLocation = @"C:\Users\Euthyphro\AppData\Roaming\PixelShoot\MapTextures\stone16x16px.png";
string spriteCollectionDataLocation = @"C:\Users\Euthyphro\AppData\Roaming\PixelShoot\MapTextures\SpriteCollection.dat";
public tk2dSpriteCollectionData spriteCollectionData;
public Texture2D texture;
tk2dBaseSprite spriteInstance = null;
void Start ()
{
CreateSpriteCollection ();
}
void CreateSpriteCollection()
{
FileManager fm = new FileManager();
if(File.Exists(spriteCollectionDataLocation))
{
spriteCollectionData = (tk2dSpriteCollectionData)fm.OpenStream(spriteCollectionDataLocation);
}
else
{
if(File.Exists(imageLocation))
{
byte[] fileData = File.ReadAllBytes(imageLocation);
spriteCollectionData = Resources.Load ("Sprites/TileMapCollection", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
texture = new Texture2D(288,270);
texture.filterMode = FilterMode.Point;
texture.LoadImage(fileData);
spriteCollectionData.textureFilterMode = FilterMode.Point;
string[] names = new string[256];
Rect[] regions = new Rect[256];
Vector2[] anchors = new Vector2[256];
for(int y = 0; y < 16; y++)
{
for(int x = 0; x < 16; x++)
{
int pos = x+(16*y);
names[x+(16*y)] = pos.ToString()+"tile";
int offsetX = x;
int offsetY = y;
if(y > 0)
{
offsetY = y*16+(2*y);
}
if(x > 0)
{
offsetX = x*16+(2*x);
}
regions[x+(16*y)] = new Rect(offsetX, offsetY, 16, 16) ;
anchors[x+(16*y)] = new Vector2(offsetX, offsetY);
spriteCollectionData = tk2dSpriteCollectionData.CreateFromTexture(texture,tk2dSpriteCollectionSize.ForTk2dCamera(), names, regions, anchors);
}
}
fm.WriteStream(spriteCollectionDataLocation, spriteCollectionData);
}
}
}
}