Esempio n. 1
0
        private void CreateSprites(ImportedAnimationInfo animations, string imageFile)
        {
            TextureImporter importer = AssetImporter.GetAtPath(imageFile) as TextureImporter;

            // adjust values for pixel art
            importer.textureType         = TextureImporterType.Sprite;
            importer.spriteImportMode    = SpriteImportMode.Multiple;
            importer.spritePixelsPerUnit = _spritePixelsPerUnit;
            importer.mipmapEnabled       = false;
            importer.filterMode          = FilterMode.Point;
            importer.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
            importer.maxTextureSize      = animations.maxTextureSize;

            // create sub sprites for this file according to the AsepriteAnimationInfo
            importer.spritesheet = animations.GetSpriteSheet(_spriteAlignment, _spriteAlignmentCustomX, _spriteAlignmentCustomY);

            EditorUtility.SetDirty(importer);

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

            AssetDatabase.ImportAsset(imageFile, ImportAssetOptions.ForceUpdate);
        }
Esempio n. 2
0
        private void CreateSprites(ImportedAnimationInfo animations, string imageFile)
        {
            TextureImporter importer = AssetImporter.GetAtPath(imageFile) as TextureImporter;

            // apply texture import settings if there are no previous ones
            if (!animations.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 = animations.GetSpriteSheet(
                sharedData.spriteAlignment,
                sharedData.spriteAlignmentCustomX,
                sharedData.spriteAlignmentCustomY);

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

            // these values will be set in any case, not influenced by previous import settings
            importer.spriteImportMode = SpriteImportMode.Multiple;
            importer.maxTextureSize   = animations.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);
        }