Exemplo n.º 1
0
 private static void GenerateMetaData(UncroppedStanding standing)
 {
     foreach (var cropper in standing.GetComponentsInChildren <SpriteCropper>())
     {
         GenerateMetaData(standing, cropper);
     }
 }
Exemplo n.º 2
0
        private static void WriteCroppedTexture(UncroppedStanding standing, SpriteCropper cropper)
        {
            var cropRect = cropper.cropRect;
            var cropped  = new Texture2D(cropRect.width, cropRect.height, TextureFormat.RGBA32, false);
            var texture  = cropper.sprite.texture;
            var pixels   = texture.GetPixels(cropRect.x, cropRect.y, cropRect.width, cropRect.height);

            cropped.SetPixels(pixels);
            cropped.Apply();

            var bytes              = cropped.EncodeToPNG();
            var fileName           = cropper.sprite.name + ".png";
            var absoluteOutputPath = Path.Combine(standing.absoluteOutputDirectory, fileName);

            Directory.CreateDirectory(Path.GetDirectoryName(absoluteOutputPath));
            File.WriteAllBytes(absoluteOutputPath, bytes);

            var assetPath = Path.Combine(standing.outputDirectory, fileName);

            AssetDatabase.ImportAsset(assetPath);
            var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (importer.textureType != TextureImporterType.Sprite)
            {
                importer.textureType = TextureImporterType.Sprite;
                importer.SaveAndReimport();
            }
        }
Exemplo n.º 3
0
        private static void WriteCropResult(UncroppedStanding standing)
        {
            foreach (var cropper in standing.GetComponentsInChildren <SpriteCropper>())
            {
                WriteCropResult(standing, cropper);
            }

            AssetDatabase.Refresh();
        }
Exemplo n.º 4
0
        private static void GenerateMetadata(UncroppedStanding standing, SpriteCropper cropper)
        {
            var meta = CreateInstance <SpriteWithOffset>();

            meta.offset = (cropper.cropRect.center - cropper.boundRect.center) / cropper.sprite.pixelsPerUnit;
            var path = Path.Combine(standing.outputDirectory, cropper.sprite.name + ".png");

            meta.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path);
            AssetDatabase.CreateAsset(meta, Path.Combine(standing.outputDirectory, cropper.sprite.name + ".asset"));
        }
Exemplo n.º 5
0
        private static void WriteCropResult(UncroppedStanding standing, SpriteCropper cropper)
        {
            var uncropped = cropper.sprite.texture;
            var cropRect  = cropper.cropRect;
            var cropped   = new Texture2D(cropRect.width, cropRect.height, TextureFormat.RGBA32, false);
            var pixels    = uncropped.GetPixels(cropRect.x, cropRect.y, cropRect.width, cropRect.height);

            cropped.SetPixels(pixels);
            cropped.Apply();
            var bytes = cropped.EncodeToPNG();

            File.WriteAllBytes(Path.Combine(standing.absoluteOutputDirectory, cropper.sprite.name + ".png"), bytes);
        }
Exemplo n.º 6
0
        private static void GenerateMetaData(UncroppedStanding standing, SpriteCropper cropper)
        {
            var cropRect  = cropper.cropRect;
            var uncropped = cropper.sprite.texture;
            var outputDir = Path.Combine("Assets", standing.outputDirectory);
            var cropped   = AssetDatabase.LoadAssetAtPath <Sprite>(
                Path.Combine(outputDir, cropper.sprite.name + ".png"));
            var meta = CreateInstance <SpriteWithOffset>();

            meta.offset = (cropRect.center - new Vector2(uncropped.width, uncropped.height) / 2.0f) /
                          cropper.sprite.pixelsPerUnit;
            meta.sprite = cropped;
            AssetDatabase.CreateAsset(meta, Path.Combine(outputDir, cropper.sprite.name + ".asset"));
        }