Пример #1
0
        public static TexturePackerAtlas create(Texture2D texture, int regionWidth, int regionHeight, int maxRegionCount = int.MaxValue, int margin = 0, int spacing = 0)
        {
            var textureAtlas = new TexturePackerAtlas(texture);
            var count        = 0;
            var width        = texture.width - margin;
            var height       = texture.height - margin;
            var xIncrement   = regionWidth + spacing;
            var yIncrement   = regionHeight + spacing;

            for (var y = margin; y < height; y += yIncrement)
            {
                for (var x = margin; x < width; x += xIncrement)
                {
                    var regionName = string.Format("{0}{1}", texture.name ?? "region", count);
                    textureAtlas.createRegion(regionName, x, y, regionWidth, regionHeight);
                    count++;

                    if (count >= maxRegionCount)
                    {
                        return(textureAtlas);
                    }
                }
            }

            return(textureAtlas);
        }
Пример #2
0
        public static TexturePackerAtlas create(TexturePackerFile f, string folder)
        {
            Texture2D          texture = Resources.Load(folder + "/" + Utils.RemoveFileExtension(f.meta.image), typeof(Texture2D)) as Texture2D;
            TexturePackerAtlas atlas   = new TexturePackerAtlas(texture);

            for (var i = 0; i < f.frames.Count; i++)
            {
                atlas.createRegion
                (
                    name: f.frames[i].filename,
                    x: f.frames[i].frame.x,
                    y: f.frames[i].frame.y,
                    width: f.frames[i].frame.w,
                    height: f.frames[i].frame.h
                );
            }
            return(atlas);
        }