diff --git a/.gitignore b/.gitignore index d6333d1..815aee7 100755 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,7 @@ Packages/sh.orels.shaders.inspector/Editor/MaterialLibraries/Resources/**/*.json /Assets/_PoiyomiShaders /Assets/_PoiyomiShaders.meta /Thry +/Exports /Assets/Samples /Assets/Samples.meta diff --git a/Assets/Tools/Editor/ReleaseExporter.cs b/Assets/Tools/Editor/ReleaseExporter.cs index b497136..9461f5a 100755 --- a/Assets/Tools/Editor/ReleaseExporter.cs +++ b/Assets/Tools/Editor/ReleaseExporter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Linq; using UnityEditor; using UnityEngine; @@ -67,17 +68,23 @@ private static void ExportAsUnityPackage() var exportDir = Path.Combine(Directory.GetCurrentDirectory(), "Exports"); Directory.CreateDirectory(exportDir); - ExportAsUnityPackage(_exportFolders, ignored, Path.Combine(exportDir, $"sh.orels.shaders-combined-{manifest.version}.unitypackage"), manifest.version); - ExportAsUnityPackage(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-standalone-{manifest.version}.unitypackage"), manifest.version); - ExportAsUnityPackage(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-standalone-{manifest.version}.unitypackage"), manifest.version); - ExportAsUnityPackage(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-standalone-{manifest.version}.unitypackage"), manifest.version); + // Export .unitypackage files + ExportAsUnityPackage(_exportFolders, ignored, Path.Combine(exportDir, $"sh.orels.shaders-combined-{manifest.version}.unitypackage")); + ExportAsUnityPackage(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-standalone-{manifest.version}.unitypackage")); + ExportAsUnityPackage(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-standalone-{manifest.version}.unitypackage")); + ExportAsUnityPackage(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-standalone-{manifest.version}.unitypackage")); + + // Export .zip files + ExportAsZip(_exportFolders[0], ignored, Path.Combine(exportDir, $"sh.orels.shaders-{manifest.version}.zip")); + ExportAsZip(_exportFolders[1], ignored, Path.Combine(exportDir, $"sh.orels.shaders.inspector-{manifest.version}.zip")); + ExportAsZip(_exportFolders[2], ignored, Path.Combine(exportDir, $"sh.orels.shaders.generator-{manifest.version}.zip")); // Open the export folder var exportedPath = new FileInfo("Exports").FullName; Process.Start(exportedPath); } - private static void ExportAsUnityPackage(string[] baseFolders, List ingored, string exportPath, string version) + private static void ExportAsUnityPackage(string[] baseFolders, List ingored, string exportPath) { var list = baseFolders.SelectMany(f => Directory.GetFiles(f, "*", SearchOption.AllDirectories)) .Select(f => f.Replace('/', '\\')) @@ -88,7 +95,7 @@ private static void ExportAsUnityPackage(string[] baseFolders, List ingo AssetDatabase.ExportPackage(list, exportPath, ExportPackageOptions.Recurse); } - private static void ExportAsUnityPackage(string baseFolder, List ingored, string exportPath, string version) + private static void ExportAsUnityPackage(string baseFolder, List ingored, string exportPath) { var list = Directory.GetFiles(baseFolder, "*", SearchOption.AllDirectories) .Select(f => f.Replace('/', '\\')) @@ -96,5 +103,30 @@ private static void ExportAsUnityPackage(string baseFolder, List ingored .ToArray(); AssetDatabase.ExportPackage(list, exportPath, ExportPackageOptions.Recurse); } + + private static void ExportAsZip(string baseFolder, List ingored, string exportPath) + { + var list = Directory.GetFiles(baseFolder, "*", SearchOption.AllDirectories) + .Select(f => f.Replace('/', '\\')) + .Where(f => !ingored.Any(i => f.Contains(i, StringComparison.InvariantCultureIgnoreCase))) + .ToArray(); + + if (File.Exists(exportPath)) File.Delete(exportPath); + var basePath = baseFolder.Replace('/', '\\') + '\\'; + using (var zip = new ZipArchive(File.OpenWrite(exportPath), ZipArchiveMode.Create)) + { + foreach (var file in list) + { + var entry = zip.CreateEntry(file.Replace(basePath, "")); + using (var stream = File.OpenRead(file)) + { + using (var entryStream = entry.Open()) + { + stream.CopyTo(entryStream); + } + } + } + } + } } } \ No newline at end of file