Exemplo n.º 1
0
        public DicedTexture Dice(SourceTexture source)
        {
            var texture    = source.Texture;
            var units      = new List <DicedUnit>();
            var unitCountX = Mathf.CeilToInt((float)texture.width / unitSize);
            var unitCountY = Mathf.CeilToInt((float)texture.height / unitSize);

            for (int unitX = 0; unitX < unitCountX; unitX++)
            {
                for (int unitY = 0; unitY < unitCountY; unitY++)
                {
                    var x          = unitX * unitSize;
                    var y          = unitY * unitSize;
                    var pixelsRect = new RectInt(x, y, unitSize, unitSize);
                    var pixels     = GetPixels(texture, pixelsRect);
                    if (pixels.All(p => p.a == 0))
                    {
                        continue;
                    }
                    var paddedRect   = PadRect(pixelsRect, padding);
                    var paddedPixels = GetPixels(texture, paddedRect);
                    var quadVerts    = CropOverBorders(pixelsRect, x, y, texture);
                    var hash         = GetHash(unitSize, pixels);
                    var dicedUnit    = new DicedUnit(quadVerts, paddedPixels, hash);
                    units.Add(dicedUnit);
                }
            }

            return(new DicedTexture(source, units));
        }
Exemplo n.º 2
0
 public DicedTexture(SourceTexture source, IEnumerable <DicedUnit> units)
 {
     Source      = source;
     Units       = units?.ToArray() ?? throw new ArgumentNullException(nameof(units));
     UniqueUnits = Units.Distinct().ToArray();
 }