private bool GenerateSprites()
        {
            TextureImporter importer = AssetImporter.GetAtPath(filePath) as TextureImporter;

            if (importer == null)
            {
                return(false);
            }

            importer.textureType         = TextureImporterType.Sprite;
            importer.spritePixelsPerUnit = Settings.pixelsPerUnit;
            importer.mipmapEnabled       = false;
            importer.filterMode          = FilterMode.Point;

            var metaList   = CreateMetaData(fileName);
            var properties = AseSpritePostProcess.GetPhysicsShapeProperties(importer, metaList);

            importer.spritesheet        = metaList.ToArray();
            importer.textureCompression = TextureImporterCompression.Uncompressed;
            importer.spriteImportMode   = SpriteImportMode.Multiple;

            EditorUtility.SetDirty(importer);
            try {
                importer.SaveAndReimport();
            } catch (Exception e) {
                Debug.LogWarning("There was a problem with generating sprite file: " + e);
            }

            AseSpritePostProcess.RecoverPhysicsShapeProperty(properties);
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
            return(true);
        }
Beispiel #2
0
        private bool GenerateSprites(string path, Vector2Int size)
        {
            this.size = size;

            var             fileName = Path.GetFileNameWithoutExtension(path);
            TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;

            if (importer == null)
            {
                return(false);
            }

            //TextureImporterSettings textSetting = new TextureImporterSettings();
            //importer.ReadTextureSettings(textSetting);
            importer.textureType         = TextureImporterType.Sprite;
            importer.spritePixelsPerUnit = Settings.pixelsPerUnit;
            importer.mipmapEnabled       = false;
            importer.filterMode          = FilterMode.Point;
            var metaList      = CreateMetaData(fileName);
            var oldProperties = AseSpritePostProcess.GetPhysicsShapeProperties(importer, metaList);

            importer.spritesheet        = metaList.ToArray();
            importer.textureCompression = TextureImporterCompression.Uncompressed;
            importer.spriteImportMode   = SpriteImportMode.Multiple;

            EditorUtility.SetDirty(importer);
            try {
                //textSetting.spriteMeshType = SpriteMeshType.FullRect;
                //importer.SetTextureSettings(textSetting);

                importer.SaveAndReimport();
            } catch (Exception e) {
                Debug.LogWarning("There was a problem with generating sprite file: " + e);
            }

            var newProperties = AseSpritePostProcess.GetPhysicsShapeProperties(importer, metaList);

            AseSpritePostProcess.RecoverPhysicsShapeProperty(newProperties, oldProperties);
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
            return(true);
        }