private static Texture2D UpdateUIAtlas(UIAtlas atlas, List <Texture2D> textures, ref int?size, out int minSize, UITexturePacker.FreeRectChoiceHeuristic heuristic) { Debug.Log("***************** Updating atlas " + atlas.name + " - " + DateTime.Now); Rect[] texRects; Texture2D newTexture = CreateTexture(textures.ToArray(), ref size, 1, out texRects, out minSize, heuristic); List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures.Cast <Texture>().ToList()); for (int i = 0; i < sprites.Count; i++) { Rect rect = NGUIMath.ConvertToPixels(texRects[i], newTexture.width, newTexture.height, true); UIAtlasMaker.SpriteEntry se = sprites[i]; se.x = Mathf.RoundToInt(rect.x); se.y = Mathf.RoundToInt(rect.y); se.width = Mathf.RoundToInt(rect.width); se.height = Mathf.RoundToInt(rect.height); } // Replace the sprites within the atlas UIAtlasMaker.ReplaceSprites(atlas, sprites); // Release the temporary textures UIAtlasMaker.ReleaseSprites(sprites); return(newTexture); }
private void AddOrUpdate(UIAtlas atlas, List <SpriteEntry> sprites) { if (sprites.Count > 0) { // Combine all sprites into a single texture and save it if (UIAtlasMaker.UpdateTexture(atlas, sprites)) { // Replace the sprites within the atlas UIAtlasMaker.ReplaceSprites(atlas, sprites); } // Release the temporary textures UIAtlasMaker.ReleaseSprites(sprites); EditorUtility.ClearProgressBar(); return; } }
static private void UpdateUIAtlas(UIAtlas atlas, List <UIAtlasMaker.SpriteEntry> sprites, out Texture2D atlasTex) { atlasTex = null; if ( (null == atlas) || (null == sprites) || (0 == sprites.Count) ) { return; } if (UpdateTexture(atlas, sprites, out atlasTex)) { UIAtlasMaker.ReplaceSprites(atlas, sprites); } UIAtlasMaker.ReleaseSprites(sprites); atlas.MarkAsChanged(); }