public override Guid GetExportHash(UnityEngine.Texture2D texture) { var bytes = new List <byte>(); // Add tiny texture settings bytes var settings = Texture2DAsset.GetSettings(texture); var settingsJson = UnityEditor.EditorJsonUtility.ToJson(settings); bytes.AddRange(Encoding.ASCII.GetBytes(settingsJson)); // Add texture importer settings bytes var assetPath = UnityEditor.AssetDatabase.GetAssetPath(texture); if (!string.IsNullOrEmpty(assetPath)) { var importer = UnityEditor.AssetImporter.GetAtPath(assetPath) as UnityEditor.TextureImporter; if (importer != null) { var importerJson = UnityEditor.EditorJsonUtility.ToJson(importer); bytes.AddRange(Encoding.ASCII.GetBytes(importerJson)); } } // Add image content hash bytes var contentHash = texture.imageContentsHash.ToString(); bytes.AddRange(Encoding.ASCII.GetBytes(contentHash)); // New guid from bytes return(GuidUtility.NewGuid(bytes.ToArray())); }
public override IEnumerable <FileInfo> Export(FileInfo outputFile, UnityEngine.Texture2D texture) { var settings = Texture2DAsset.GetSettings(texture); var formatType = Texture2DAsset.RealFormatType(texture, settings); switch (formatType) { case TextureFormatType.Source: return(AssetExporter.ExportSource(outputFile, texture)); case TextureFormatType.PNG: return(ExportPng(outputFile, texture)); case TextureFormatType.JPG: //return ExportJpg(outputFile, Object, settings.JpgCompressionQuality); return(ExportJpgOptimized(outputFile, texture, settings.JpgCompressionQuality)); case TextureFormatType.WebP: return(ExportWebP(outputFile, texture, settings.WebPCompressionQuality)); default: throw new InvalidEnumArgumentException(nameof(formatType), (int)formatType, formatType.GetType()); } }