示例#1
0
        private static List <AtlasTexture> Pack(Texture2D[] textures,
                                                float uvInset = 0, bool square = false, int sizeLimit = 8, int unitSize = 1, int padding = 0)
        {
            // TODO: Don't use dicer here; create mock diced textures instead.
            var dicer         = new TextureDicer(unitSize, padding);
            var dicedTextures = textures.Select(t => new SourceTexture(t.name, t)).Select(dicer.Dice);
            var serializer    = new MockTextureSerializer();
            var packer        = new TexturePacker(serializer, uvInset, square, sizeLimit, unitSize, padding);

            return(packer.Pack(dicedTextures));
        }
        private static List <Sprite> Build(string[] texturePaths, float uvInset = 0, bool square = false, int sizeLimit = 8,
                                           int unitSize = 1, int padding = 0, float ppu = 1, Vector2 pivot = default, bool keepOriginalPivot = false)
        {
            // TODO: Don't use loader, dicer and packer here; create mock atlas textures instead.
            var textureLoader  = new TextureLoader();
            var sourceTextures = texturePaths.Select(textureLoader.Load);
            var dicer          = new TextureDicer(unitSize, padding);
            var dicedTextures  = sourceTextures.Select(dicer.Dice);
            var serializer     = new MockTextureSerializer();
            var packer         = new TexturePacker(serializer, uvInset, square, sizeLimit, unitSize, padding);
            var atlasTextures  = packer.Pack(dicedTextures);
            var builder        = new SpriteBuilder(ppu, pivot, keepOriginalPivot);
            var sprites        = new List <Sprite>();

            foreach (var atlasTexture in atlasTextures)
            {
                foreach (var dicedTexture in atlasTexture.DicedTextures)
                {
                    sprites.Add(builder.Build(atlasTexture, dicedTexture));
                }
            }
            return(sprites);
        }