Ejemplo n.º 1
0
        private void CreateSprites(ImportedAnimationSheet animationSheet, AnimationImportJob job)
        {
            if (animationSheet == null)
            {
                return;
            }

            string imageAssetFile = job.ImageAssetFilename;

            TextureImporter importer = AssetImporter.GetAtPath(imageAssetFile) as TextureImporter;

            // Apply texture import settings if there are no previous ones
            if (!animationSheet.HasPreviousTextureImportSettings)
            {
                importer.textureType         = TextureImporterType.Sprite;
                importer.spritePixelsPerUnit = SharedData.SpritePixelsPerUnit;
                importer.mipmapEnabled       = false;
                importer.filterMode          = FilterMode.Point;
#if UNITY_5_5_OR_NEWER
                importer.textureCompression = TextureImporterCompression.Uncompressed;
#else
                importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
#endif
            }

            // Create sub sprites for this file according to the AsepriteAnimationInfo
            if (animationSheet.UsePivot)
            {
                importer.spritesheet = animationSheet.GetSpriteSheet(SpriteAlignment.Custom, animationSheet.Pivot);
            }
            else
            {
                importer.spritesheet = animationSheet.GetSpriteSheet(SharedData.SpriteAlignment, new Vector2(SharedData.SpriteAlignmentCustomX, SharedData.SpriteAlignmentCustomY));
            }

            // Reapply old import settings (pivot settings for sprites)
            if (animationSheet.HasPreviousTextureImportSettings)
            {
                animationSheet.PreviousImportSettings.ApplyPreviousTextureImportSettings(importer);
            }

            // These values will be set in any case, not influenced by previous import settings
            importer.spriteImportMode = SpriteImportMode.Multiple;
            importer.maxTextureSize   = animationSheet.MaxTextureSize;

            EditorUtility.SetDirty(importer);

            try {
                importer.SaveAndReimport();
            }
            catch (Exception e) {
                Debug.LogWarning("There was a problem with applying settings to the generated sprite file: " + e.ToString());
            }

            AssetDatabase.ImportAsset(imageAssetFile, ImportAssetOptions.ForceUpdate);

            Sprite[] createdSprites = GetAllSpritesFromAssetFile(imageAssetFile);
            animationSheet.ApplyCreatedSprites(createdSprites);
        }
Ejemplo n.º 2
0
        private void CreateSprites(ImportedAnimationSheet animationSheet)
        {
            string imageFile = GetImageAssetFilename(animationSheet.basePath, animationSheet.name);

            TextureImporter importer = AssetImporter.GetAtPath(imageFile) as TextureImporter;

            // apply texture import settings if there are no previous ones
            if (!animationSheet.hasPreviousTextureImportSettings)
            {
                importer.textureType         = TextureImporterType.Sprite;
                importer.spritePixelsPerUnit = sharedData.spritePixelsPerUnit;
                importer.mipmapEnabled       = false;
                importer.filterMode          = FilterMode.Point;
                importer.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
            }

            // create sub sprites for this file according to the AsepriteAnimationInfo
            importer.spritesheet = animationSheet.GetSpriteSheet(
                sharedData.spriteAlignment,
                sharedData.spriteAlignmentCustomX,
                sharedData.spriteAlignmentCustomY);

            // reapply old import settings (pivot settings for sprites)
            if (animationSheet.hasPreviousTextureImportSettings)
            {
                animationSheet.previousImportSettings.ApplyPreviousTextureImportSettings(importer);
            }

            // these values will be set in any case, not influenced by previous import settings
            importer.spriteImportMode = SpriteImportMode.Multiple;
            importer.maxTextureSize   = animationSheet.maxTextureSize;

            EditorUtility.SetDirty(importer);

            try
            {
                importer.SaveAndReimport();
            }
            catch (Exception e)
            {
                Debug.LogWarning("There was a problem with applying settings to the generated sprite file: " + e.ToString());
            }

            AssetDatabase.ImportAsset(imageFile, ImportAssetOptions.ForceUpdate);

            Sprite[] createdSprites = GetAllSpritesFromAssetFile(imageFile);
            animationSheet.ApplyCreatedSprites(createdSprites);
        }