Exemple #1
0
    public void SlicesAwkwardSize()
    {
        var expectedImporter    = AssetImporter.GetAtPath(pathToExpectedOffset) as TextureImporter;
        var expectedSpritesheet = expectedImporter.spritesheet;

        var slicingOptions = new SpriteSlicingOptions();

        slicingOptions.CellSize      = new Vector2(80, 80);
        slicingOptions.ImportMode    = UnityEditor.SpriteImportMode.Multiple;
        slicingOptions.Pivot         = SpriteAlignment.Center;
        slicingOptions.SlicingMethod = SpriteSlicingOptions.GridSlicingMethod.SliceAll;
        SpriteMetaData[] createdSpritesheet = SpriteSlicer.CreateSpriteSheetForTexture(SampleTexture, slicingOptions);

        CompareFirstAndLastRects(expectedSpritesheet, createdSpritesheet);
    }
Exemple #2
0
    public void CorrectlySlices()
    {
        var expectedImporter    = AssetImporter.GetAtPath(pathToExpectedOffset) as TextureImporter;
        var expectedSpritesheet = expectedImporter.spritesheet;

        var slicingOptions = new SpriteSlicingOptions();

        slicingOptions.CellSize      = new Vector2(86, 86);
        slicingOptions.ImportMode    = UnityEditor.SpriteImportMode.Multiple;
        slicingOptions.Pivot         = SpriteAlignment.Center;
        slicingOptions.SlicingMethod = SpriteSlicingOptions.GridSlicingMethod.SliceAll;
        SpriteMetaData[] createdSpritesheet = SpriteSlicer.CreateSpriteSheetForTexture(SampleTexture, slicingOptions);

        Assert.AreEqual(expectedSpritesheet.Length, createdSpritesheet.Length,
                        "Number of Slices not equal to NumExpectedSlices");
    }
        public static SpriteFileSettings FromString(string serialized)
        {
            var fileSettings = new SpriteFileSettings();

            string[] entries = serialized.Split(new char[] { delimeterChar }, System.StringSplitOptions.None);
            // Support old format
            if (entries.Length == 3)
            {
                fileSettings.SlicingOptions = SpriteSlicingOptions.FromString(serialized);
            }
            else
            {
                fileSettings.OverridePackingTag = bool.Parse(entries[0]);
                fileSettings.PackingTag         = entries[1];

                int startingIndex = entries[0].Length + entries[1].Length + 2;

                string serializedSlicingOptions = serialized.Substring(startingIndex,
                                                                       serialized.Length - startingIndex);
                fileSettings.SlicingOptions = SpriteSlicingOptions.FromString(serializedSlicingOptions);
            }

            return(fileSettings);
        }