How to packageAtlas at Runtime by tk2dSpriteCollectionData.CreateFromTexture ?
I can not have right rect[] and anchors[] I think.
I used Texture2D.PackTextures to package multi texture into tk2dSpriteCollectionData, it seems loaded but regions and anchors are wrong.
What should I do to make them right?
I am using tk2dcamera
Code attached.
private static tk2dSpriteCollectionSize sz2 = tk2dSpriteCollectionSize.ForTk2dCamera ();
public static tk2dSpriteCollectionData packCoreIngredientCollectionData (ArrayList ingre)
{
int s = ingre.Count;
string[] ids = new string;
Texture2D[] atlas = new Texture2D;
Texture2D packed = new Texture2D (512, 1024);
IEnumerator ie = ingre.GetEnumerator ();
int i = 0;
while (ie.MoveNext()) {
string id = ie.Current.ToString ();
ids = id;
string path = "INGREDIENT/" + id;
Texture2D t = Resources.Load (path) as Texture2D;
atlas = t;
i++;
}
Rect[] rects = packed.PackTextures (atlas, 0 );
Vector2[] anchors = new Vector2;
int k = 0;
foreach (Rect r in rects) {
float xx = r.width/2;
Debug.Log(xx);
float yy = r.x + xx;
Debug.Log(yy);
//anchors [k] = new Vector2 (r.x + r.width / 2, r.y + r.height / 2);
anchors [k] = new Vector2 (r.width / 2, r.height / 2);
Debug.Log(r);
Debug.Log(anchors[k]);
k++;
}
tk2dSpriteCollectionData data = tk2dSpriteCollectionData.CreateFromTexture (packed, sz2, ids, rects, anchors);
return data;
}