- Home /
I've got my sprites packed into a texture, and I've got their coordinates. How do I turn that into an NGUI atlas?
I need to create an NGUI atlas at run time, and I think I'm close:
// Create the texture and pack the sprites into it.
var testTexture = new Texture2D(1, 1);
var coordinates = testTexture.PackTextures(textures.ToArray(), 0);
// Get the atlas game object (just a GameObject that I added to the scene with a UIAtlas attached to it) and set its texture to the packed texture.
var atlas = GameObject.Find("MyAtlas").GetComponent<UIAtlas>();
atlas.spriteMaterial.mainTexture = testTexture;
// Add a sprite object with the coordinates from PackTextures and att it to the atlas's spriteList.
for(int i = 0; i < coordinates.Count; i++)
{
var coordinate = coordinates[i];
var sprite = new UIAtlas.Sprite();
sprite.name = names[i];
sprite.inner = coordinate;
sprite.outer = coordinate;
atlas.spriteList.Add(sprite);
atlas.MarkAsDirty();
}
This almost works. The atlas object does have a sprite list with the correct names, but the sprites are either blank or they have odd rectangles instead of their actual images. The dimensions are also either 0 or 1, and I'm thinking it's because the coordinates that I get back from PackTextures are between 0.0 and 1.0. Is there some step that I need to take to multiply the atlas's size?
What do I need to do to properly create my atlas?
did you ask in the forums? - if you did and you got your answer, post it so that others benefit from it :)
Answer by davebuchhofer · Aug 26, 2013 at 12:26 AM
Set the atlas to be in Texture Coordinates instead of in Pixels.
Your answer
Follow this Question
Related Questions
Duplicate Texture Memory with Sprite Atlas 0 Answers
NGUI Texture atlas help ! 1 Answer
How do I change the Mip Bias of a Sprite Atlas? 1 Answer
Why don't four 512x512 images atlas into one 1024x1024? 1 Answer
Change texure on NGUI BUTTUN press 0 Answers