Esempio n. 1
0
        public static List <SpriteDefinition> GenerateAtlasMetaData(ImportContext ctx,
                                                                    SpritePacker.PackResult packResult)
        {
            var oldPivotNorm = ctx.Settings.PivotRelativePos;
            var metaList     = new List <SpriteDefinition>();

            for (int i = 0; i < packResult.Positions.Count; ++i)
            {
                var pos    = packResult.Positions[i];
                var image  = pos.FrameImage;
                var name   = pos.FrameImage.BaseName + "_" + pos.FrameImage.FrameId + "_" + pos.FrameImage.SubImageIndex;
                var bounds = new Rect(pos.X, pos.Y, pos.Width, pos.Height);
                var md     = GenerateSpriteMetaData(image, name, bounds, oldPivotNorm);
                metaList.Add(new SpriteDefinition(md, image));
            }

            return(metaList);
        }
Esempio n. 2
0
        public static Texture2D CreateTexture(SpritePacker.PackResult packResult)
        {
            var texture = CreateEmptyTexture(packResult.AtlasTextureSize);

            foreach (var pos in packResult.Positions)
            {
                var image = pos.FrameImage;
                var bb    = image.BoundingBox;

                for (var y = bb.MinY; y < bb.MaxY; ++y)
                {
                    for (var x = bb.MinX; x < bb.MaxX; ++x)
                    {
                        var texX = (x - bb.MinX) + pos.X;
                        var texY = -(y - bb.MinY) + pos.Y + bb.Height - 1;
                        texture.SetPixel(texX, texY, image[x, y]);
                    }
                }
            }

            texture.Apply();
            return(texture);
        }