update libs
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2072d354c04b19c48b22593536b3ebcf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal interface IPackageExporter
|
||||
{
|
||||
PackageExporterSettings Settings { get; }
|
||||
|
||||
Task<PackageExporterResult> Export();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41bc3a111ed1fd64c8b9acef211d9e51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/Abstractions/IPackageExporter.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal interface IPreviewInjector
|
||||
{
|
||||
void Inject(string temporaryPackagePath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcff58dc716351f43b2709cfacdfebba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/Abstractions/IPreviewInjector.cs
|
||||
uploadId: 724584
|
||||
@@ -8,47 +8,51 @@ using UnityEditor;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal abstract class PackageExporter
|
||||
internal abstract class PackageExporterBase : IPackageExporter
|
||||
{
|
||||
protected const string ProgressBarTitle = "Exporting Package";
|
||||
protected const string ProgressBarStepSavingAssets = "Saving Assets...";
|
||||
protected const string ProgressBarStepGatheringFiles = "Gathering files...";
|
||||
protected const string ProgressBarStepCompressingPackage = "Compressing package...";
|
||||
public PackageExporterSettings Settings { get; private set; }
|
||||
|
||||
public const string ProgressBarTitle = "Exporting Package";
|
||||
public const string ProgressBarStepSavingAssets = "Saving Assets...";
|
||||
public const string ProgressBarStepGatheringFiles = "Gathering files...";
|
||||
public const string ProgressBarStepGeneratingPreviews = "Generating previews...";
|
||||
public const string ProgressBarStepCompressingPackage = "Compressing package...";
|
||||
|
||||
private static readonly string[] PluginFolderExtensions = { "androidlib", "bundle", "plugin", "framework", "xcframework" };
|
||||
|
||||
public static async Task<ExportResult> ExportPackage(ExporterSettings exportSettings)
|
||||
public PackageExporterBase(PackageExporterSettings settings)
|
||||
{
|
||||
if (!IsSettingsValid(exportSettings, out Exception e))
|
||||
return new ExportResult() { Success = false, Error = ASError.GetGenericError(e) };
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
switch (exportSettings)
|
||||
public async Task<PackageExporterResult> Export()
|
||||
{
|
||||
try
|
||||
{
|
||||
case LegacyExporterSettings legacySettings:
|
||||
return await PackageExporterLegacy.ExportPackage(legacySettings);
|
||||
case DefaultExporterSettings defaultSettings:
|
||||
return PackageExporterDefault.ExportPackage(defaultSettings);
|
||||
default:
|
||||
return new ExportResult() { Success = false, Error = ASError.GetGenericError(new ArgumentException("Unrecognized ExportSettings type was provided")) };
|
||||
ValidateSettings();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageExporterResult() { Success = false, Exception = e };
|
||||
}
|
||||
|
||||
return await ExportImpl();
|
||||
}
|
||||
|
||||
private static bool IsSettingsValid(ExporterSettings settings, out Exception e)
|
||||
protected virtual void ValidateSettings()
|
||||
{
|
||||
e = null;
|
||||
if (Settings == null)
|
||||
throw new ArgumentException("Settings cannot be null");
|
||||
|
||||
if (settings == null)
|
||||
e = new ArgumentException("Package Exporting failed: ExporterSettings cannot be null");
|
||||
else if (settings.ExportPaths == null || settings.ExportPaths.Length == 0)
|
||||
e = new ArgumentException("Package Exporting failed: received an invalid export paths array");
|
||||
else if (string.IsNullOrEmpty(settings.OutputFilename))
|
||||
e = new ArgumentException("Package Exporting failed: received an invalid output path");
|
||||
else if (settings.OutputFilename.EndsWith("/") || settings.OutputFilename.EndsWith("\\"))
|
||||
e = new ArgumentException("Package Exporting failed: output path must be a valid filename and not end with a directory separator character");
|
||||
if (string.IsNullOrEmpty(Settings.OutputFilename))
|
||||
throw new ArgumentException("Output path cannot be null");
|
||||
|
||||
return e == null;
|
||||
if (Settings.OutputFilename.EndsWith("/") || Settings.OutputFilename.EndsWith("\\"))
|
||||
throw new ArgumentException("Output path must be a valid filename and not end with a directory separator character");
|
||||
}
|
||||
|
||||
protected abstract Task<PackageExporterResult> ExportImpl();
|
||||
|
||||
protected string[] GetAssetPaths(string rootPath)
|
||||
{
|
||||
// To-do: slight optimization is possible in the future by having a list of excluded folders/file extensions
|
||||
@@ -70,19 +74,9 @@ namespace AssetStoreTools.Exporter
|
||||
return paths.ToArray();
|
||||
}
|
||||
|
||||
protected string GetAssetGuid(string assetPath, bool generateForPlugin, bool hiddenSearch)
|
||||
protected string GetAssetGuid(string assetPath, bool generateIfPlugin, bool scrapeFromMeta)
|
||||
{
|
||||
// Skip meta files as they do not have guids
|
||||
if (assetPath.EndsWith(".meta", StringComparison.OrdinalIgnoreCase))
|
||||
return string.Empty;
|
||||
|
||||
// Skip hidden assets. They normally do not have meta files, but
|
||||
// have been observed to retain them in the past due to a Unity bug
|
||||
if (assetPath.EndsWith("~"))
|
||||
return string.Empty;
|
||||
|
||||
var assetName = assetPath.Split('/').Last();
|
||||
if (assetName.StartsWith("."))
|
||||
if (!FileUtility.ShouldHaveMeta(assetPath))
|
||||
return string.Empty;
|
||||
|
||||
// Skip ProjectVersion.txt file specifically as it may introduce
|
||||
@@ -97,16 +91,15 @@ namespace AssetStoreTools.Exporter
|
||||
|
||||
// Some special folders (e.g. SomeName.framework) do not have meta files inside them.
|
||||
// Their contents should be exported with any arbitrary GUID so that Unity Importer could pick them up
|
||||
if (generateForPlugin && PathBelongsToPlugin(assetPath))
|
||||
if (generateIfPlugin && PathBelongsToPlugin(assetPath))
|
||||
return GUID.Generate().ToString();
|
||||
|
||||
// Files in hidden folders (e.g. Samples~) are not part of the Asset Database,
|
||||
// therefore GUIDs need to be scraped from the .meta file.
|
||||
// Note: only do this for custom exporter since the native exporter
|
||||
// Note: only do this for non-native exporter since the native exporter
|
||||
// will not be able to retrieve the asset path from a hidden folder
|
||||
if (hiddenSearch)
|
||||
if (scrapeFromMeta)
|
||||
{
|
||||
// To-do: handle hidden folders without meta files
|
||||
var metaPath = $"{assetPath}.meta";
|
||||
|
||||
if (!File.Exists(metaPath))
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aab20a0b596e60b40b1f7f7e0f54858e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/Abstractions/PackageExporterBase.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal abstract class PackageExporterSettings
|
||||
{
|
||||
public string OutputFilename;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82c350daaabdc784e95e09cdc8511e23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/Abstractions/PackageExporterSettings.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,11 @@
|
||||
using AssetStoreTools.Previews.Generators;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class DefaultExporterSettings : PackageExporterSettings
|
||||
{
|
||||
public string[] ExportPaths;
|
||||
public string[] Dependencies;
|
||||
public IPreviewGenerator PreviewGenerator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92cbd0e60b4bb9049bcf1e9fd92ccae6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/DefaultExporterSettings.cs
|
||||
uploadId: 724584
|
||||
@@ -1,35 +1,43 @@
|
||||
using AssetStoreTools.Uploader.Utility;
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using AssetStoreTools.Utility;
|
||||
using AssetStoreTools.Utility.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using CacheConstants = AssetStoreTools.Constants.Cache;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class PackageExporterDefault : PackageExporter
|
||||
internal class DefaultPackageExporter : PackageExporterBase
|
||||
{
|
||||
private const string TemporaryExportPathName = "CustomExport";
|
||||
|
||||
private DefaultExporterSettings _exportSettings;
|
||||
private DefaultExporterSettings _defaultExportSettings;
|
||||
|
||||
private PackageExporterDefault(DefaultExporterSettings exportSettings)
|
||||
public DefaultPackageExporter(DefaultExporterSettings settings) : base(settings)
|
||||
{
|
||||
_exportSettings = exportSettings;
|
||||
_defaultExportSettings = settings;
|
||||
}
|
||||
|
||||
public static ExportResult ExportPackage(DefaultExporterSettings exportSettings)
|
||||
protected override void ValidateSettings()
|
||||
{
|
||||
var exporter = new PackageExporterDefault(exportSettings);
|
||||
return exporter.ExportPackage();
|
||||
base.ValidateSettings();
|
||||
|
||||
if (_defaultExportSettings.ExportPaths == null || _defaultExportSettings.ExportPaths.Length == 0)
|
||||
throw new ArgumentException("Export paths array cannot be empty");
|
||||
}
|
||||
|
||||
private ExportResult ExportPackage()
|
||||
protected override async Task<PackageExporterResult> ExportImpl()
|
||||
{
|
||||
return await this.Export();
|
||||
}
|
||||
|
||||
private new async Task<PackageExporterResult> Export()
|
||||
{
|
||||
ASDebug.Log("Using custom package exporter");
|
||||
|
||||
@@ -40,6 +48,7 @@ namespace AssetStoreTools.Exporter
|
||||
try
|
||||
{
|
||||
// Create a temporary export path
|
||||
PostExportCleanup();
|
||||
var temporaryExportPath = GetTemporaryExportPath();
|
||||
if (!Directory.Exists(temporaryExportPath))
|
||||
Directory.CreateDirectory(temporaryExportPath);
|
||||
@@ -47,17 +56,20 @@ namespace AssetStoreTools.Exporter
|
||||
// Construct an unzipped package structure
|
||||
CreateTempPackageStructure(temporaryExportPath);
|
||||
|
||||
var previewGenerationResult = await GeneratePreviews();
|
||||
InjectPreviews(previewGenerationResult, temporaryExportPath);
|
||||
|
||||
// Build a .unitypackage file from the temporary folder
|
||||
CreateUnityPackage(temporaryExportPath, _exportSettings.OutputFilename);
|
||||
CreateUnityPackage(temporaryExportPath, _defaultExportSettings.OutputFilename);
|
||||
|
||||
EditorUtility.RevealInFinder(_exportSettings.OutputFilename);
|
||||
EditorUtility.RevealInFinder(_defaultExportSettings.OutputFilename);
|
||||
|
||||
ASDebug.Log($"Package file has been created at {_exportSettings.OutputFilename}");
|
||||
return new ExportResult() { Success = true, ExportedPath = _exportSettings.OutputFilename };
|
||||
ASDebug.Log($"Package file has been created at {_defaultExportSettings.OutputFilename}");
|
||||
return new PackageExporterResult() { Success = true, ExportedPath = _defaultExportSettings.OutputFilename, PreviewGenerationResult = previewGenerationResult };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ExportResult() { Success = false, Error = ASError.GetGenericError(e) };
|
||||
return new PackageExporterResult() { Success = false, Exception = e };
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -67,19 +79,13 @@ namespace AssetStoreTools.Exporter
|
||||
|
||||
private string GetTemporaryExportPath()
|
||||
{
|
||||
return $"{AssetStoreCache.TempCachePath}/{TemporaryExportPathName}";
|
||||
return $"{CacheConstants.TempCachePath}/{TemporaryExportPathName}";
|
||||
}
|
||||
|
||||
private void CreateTempPackageStructure(string tempOutputPath)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar(ProgressBarTitle, ProgressBarStepGatheringFiles, 0.4f);
|
||||
var pathGuidPairs = GetPathGuidPairs(_exportSettings.ExportPaths);
|
||||
|
||||
// Caching asset previews takes time, so we'll start doing it as we
|
||||
// iterate through assets and only retrieve them after generating the rest
|
||||
// of the package structure
|
||||
AssetPreview.SetPreviewTextureCacheSize(pathGuidPairs.Count + 100);
|
||||
var pathObjectPairs = new Dictionary<string, UnityEngine.Object>();
|
||||
var pathGuidPairs = GetPathGuidPairs(_defaultExportSettings.ExportPaths);
|
||||
|
||||
foreach (var pair in pathGuidPairs)
|
||||
{
|
||||
@@ -112,20 +118,15 @@ namespace AssetStoreTools.Exporter
|
||||
var previewObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(originalAssetPath);
|
||||
if (previewObject == null)
|
||||
continue;
|
||||
// Start caching the asset preview
|
||||
AssetPreview.GetAssetPreview(previewObject);
|
||||
pathObjectPairs.Add(outputAssetPath, previewObject);
|
||||
}
|
||||
|
||||
WritePreviewTextures(pathObjectPairs);
|
||||
|
||||
if (_exportSettings.Dependencies == null || _exportSettings.Dependencies.Length == 0)
|
||||
if (_defaultExportSettings.Dependencies == null || _defaultExportSettings.Dependencies.Length == 0)
|
||||
return;
|
||||
|
||||
var exportDependenciesDict = JsonValue.NewDict();
|
||||
var exportDependenciesDict = new JObject();
|
||||
var allRegistryPackages = PackageUtility.GetAllRegistryPackages();
|
||||
|
||||
foreach(var exportDependency in _exportSettings.Dependencies)
|
||||
|
||||
foreach (var exportDependency in _defaultExportSettings.Dependencies)
|
||||
{
|
||||
var registryPackage = allRegistryPackages.FirstOrDefault(x => x.name == exportDependency);
|
||||
if (registryPackage == null)
|
||||
@@ -139,7 +140,10 @@ namespace AssetStoreTools.Exporter
|
||||
exportDependenciesDict[registryPackage.name] = registryPackage.version;
|
||||
}
|
||||
|
||||
var exportManifestJson = JsonValue.NewDict();
|
||||
if (exportDependenciesDict.Count == 0)
|
||||
return;
|
||||
|
||||
var exportManifestJson = new JObject();
|
||||
exportManifestJson["dependencies"] = exportDependenciesDict;
|
||||
|
||||
var tempManifestDirectoryPath = $"{tempOutputPath}/packagemanagermanifest";
|
||||
@@ -170,64 +174,36 @@ namespace AssetStoreTools.Exporter
|
||||
return pathGuidPairs;
|
||||
}
|
||||
|
||||
private void WritePreviewTextures(Dictionary<string, UnityEngine.Object> pathObjectPairs)
|
||||
private async Task<PreviewGenerationResult> GeneratePreviews()
|
||||
{
|
||||
foreach (var kvp in pathObjectPairs)
|
||||
if (_defaultExportSettings.PreviewGenerator == null)
|
||||
return null;
|
||||
|
||||
void ReportProgress(float progress)
|
||||
{
|
||||
var obj = kvp.Value;
|
||||
var queuePreview = false;
|
||||
|
||||
switch (obj)
|
||||
{
|
||||
case Material _:
|
||||
case TerrainLayer _:
|
||||
case AudioClip _:
|
||||
case Mesh _:
|
||||
case Texture _:
|
||||
case UnityEngine.Tilemaps.Tile _:
|
||||
case GameObject _:
|
||||
queuePreview = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!queuePreview)
|
||||
continue;
|
||||
|
||||
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _);
|
||||
var preview = GetAssetPreviewFromGuid(guid);
|
||||
|
||||
if (!preview)
|
||||
continue;
|
||||
|
||||
var thumbnailWidth = Mathf.Min(preview.width, 128);
|
||||
var thumbnailHeight = Mathf.Min(preview.height, 128);
|
||||
var rt = RenderTexture.GetTemporary(thumbnailWidth, thumbnailHeight, 0, RenderTextureFormat.Default, RenderTextureReadWrite.sRGB);
|
||||
|
||||
var copy = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, false);
|
||||
|
||||
RenderTexture.active = rt;
|
||||
GL.Clear(true, true, new Color(0, 0, 0, 0));
|
||||
Graphics.Blit(preview, rt);
|
||||
copy.ReadPixels(new Rect(0, 0, copy.width, copy.height), 0, 0, false);
|
||||
copy.Apply();
|
||||
RenderTexture.active = null;
|
||||
|
||||
var bytes = copy.EncodeToPNG();
|
||||
if (bytes != null && bytes.Length > 0)
|
||||
{
|
||||
File.WriteAllBytes(kvp.Key + "/preview.png", bytes);
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt);
|
||||
EditorUtility.DisplayProgressBar(ProgressBarTitle, ProgressBarStepGeneratingPreviews, progress);
|
||||
}
|
||||
|
||||
_defaultExportSettings.PreviewGenerator.OnProgressChanged += ReportProgress;
|
||||
var result = await _defaultExportSettings.PreviewGenerator.Generate();
|
||||
_defaultExportSettings.PreviewGenerator.OnProgressChanged -= ReportProgress;
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"An error was encountered while generating previews. Exported package may be missing previews.\n{result.Exception}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Texture2D GetAssetPreviewFromGuid(string guid)
|
||||
private void InjectPreviews(PreviewGenerationResult result, string temporaryExportPath)
|
||||
{
|
||||
var method = typeof(AssetPreview).GetMethod("GetAssetPreviewFromGUID", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(string) }, null);
|
||||
var args = new object[] { guid };
|
||||
if (result == null || !result.Success)
|
||||
return;
|
||||
|
||||
return method?.Invoke(null, args) as Texture2D;
|
||||
var injector = new PreviewInjector(result);
|
||||
injector.Inject(temporaryExportPath);
|
||||
}
|
||||
|
||||
private void CreateUnityPackage(string pathToArchive, string outputPath)
|
||||
@@ -235,7 +211,7 @@ namespace AssetStoreTools.Exporter
|
||||
if (Directory.GetDirectories(pathToArchive).Length == 0)
|
||||
throw new InvalidOperationException("Unable to export package. The specified path is empty");
|
||||
|
||||
EditorUtility.DisplayProgressBar(ProgressBarTitle, ProgressBarStepCompressingPackage, 0.5f);
|
||||
EditorUtility.DisplayProgressBar(ProgressBarTitle, ProgressBarStepCompressingPackage, 0.8f);
|
||||
|
||||
// Archiving process working path will be set to the
|
||||
// temporary package path so adjust the output path accordingly
|
||||
@@ -245,7 +221,7 @@ namespace AssetStoreTools.Exporter
|
||||
#if UNITY_EDITOR_WIN
|
||||
CreateUnityPackageUniversal(pathToArchive, outputPath);
|
||||
#elif UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
|
||||
CreateUnityPackageOsxLinux(pathToArchive, outputPath);
|
||||
CreateUnityPackageOsxLinux(pathToArchive, outputPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -272,6 +248,7 @@ namespace AssetStoreTools.Exporter
|
||||
throw new Exception("Failed to compress the package");
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
|
||||
private void CreateUnityPackageOsxLinux(string pathToArchive, string outputPath)
|
||||
{
|
||||
var tarPath = "/usr/bin/tar";
|
||||
@@ -290,6 +267,7 @@ namespace AssetStoreTools.Exporter
|
||||
if (result != 0)
|
||||
throw new Exception("Failed to compress the package");
|
||||
}
|
||||
#endif
|
||||
|
||||
private int StartProcess(string processPath, string arguments, string workingDirectory)
|
||||
{
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/PackageExporterDefault.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/DefaultPackageExporter.cs
|
||||
uploadId: 724584
|
||||
@@ -1,16 +0,0 @@
|
||||
using AssetStoreTools.Utility;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class ExportResult
|
||||
{
|
||||
public bool Success;
|
||||
public string ExportedPath;
|
||||
public ASError Error;
|
||||
|
||||
public static implicit operator bool(ExportResult value)
|
||||
{
|
||||
return value != null && value.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
public abstract class ExporterSettings
|
||||
{
|
||||
public string[] ExportPaths;
|
||||
public string OutputFilename;
|
||||
}
|
||||
|
||||
public class DefaultExporterSettings : ExporterSettings
|
||||
{
|
||||
public string[] Dependencies;
|
||||
}
|
||||
|
||||
public class LegacyExporterSettings : ExporterSettings
|
||||
{
|
||||
public bool IncludeDependencies;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class LegacyExporterSettings : PackageExporterSettings
|
||||
{
|
||||
public string[] ExportPaths;
|
||||
public bool IncludeDependencies;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 399b115514c617d47a00b8c0a5e430fd
|
||||
guid: c7dea1cfe45989e4eab6fc5fd18c1e10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/ExporterSettings.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/LegacyExporterSettings.cs
|
||||
uploadId: 724584
|
||||
@@ -8,37 +8,44 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class PackageExporterLegacy : PackageExporter
|
||||
internal class LegacyPackageExporter : PackageExporterBase
|
||||
{
|
||||
private const string ExportMethodWithoutDependencies = "UnityEditor.PackageUtility.ExportPackage";
|
||||
private const string ExportMethodWithDependencies = "UnityEditor.PackageUtility.ExportPackageAndPackageManagerManifest";
|
||||
|
||||
private LegacyExporterSettings _exportSettings;
|
||||
private LegacyExporterSettings _legacyExportSettings;
|
||||
|
||||
private PackageExporterLegacy(LegacyExporterSettings exportSettings)
|
||||
public LegacyPackageExporter(LegacyExporterSettings settings) : base(settings)
|
||||
{
|
||||
_exportSettings = exportSettings;
|
||||
_legacyExportSettings = settings;
|
||||
}
|
||||
|
||||
public static async Task<ExportResult> ExportPackage(LegacyExporterSettings exportSettings)
|
||||
protected override void ValidateSettings()
|
||||
{
|
||||
var exporter = new PackageExporterLegacy(exportSettings);
|
||||
return await exporter.ExportPackage();
|
||||
base.ValidateSettings();
|
||||
|
||||
if (_legacyExportSettings.ExportPaths == null || _legacyExportSettings.ExportPaths.Length == 0)
|
||||
throw new ArgumentException("Export paths array cannot be empty");
|
||||
}
|
||||
|
||||
private async Task<ExportResult> ExportPackage()
|
||||
protected override async Task<PackageExporterResult> ExportImpl()
|
||||
{
|
||||
return await this.Export();
|
||||
}
|
||||
|
||||
private async new Task<PackageExporterResult> Export()
|
||||
{
|
||||
ASDebug.Log("Using native package exporter");
|
||||
|
||||
try
|
||||
{
|
||||
var guids = GetGuids(_exportSettings.ExportPaths, out bool onlyFolders);
|
||||
var guids = GetGuids(_legacyExportSettings.ExportPaths, out bool onlyFolders);
|
||||
|
||||
if (guids.Length == 0 || onlyFolders)
|
||||
throw new ArgumentException("Package Exporting failed: provided export paths are empty or only contain empty folders");
|
||||
|
||||
string exportMethod = ExportMethodWithoutDependencies;
|
||||
if (_exportSettings.IncludeDependencies)
|
||||
if (_legacyExportSettings.IncludeDependencies)
|
||||
exportMethod = ExportMethodWithDependencies;
|
||||
|
||||
var split = exportMethod.Split('.');
|
||||
@@ -52,22 +59,22 @@ namespace AssetStoreTools.Exporter
|
||||
|
||||
ASDebug.Log("Invoking native export method");
|
||||
|
||||
method?.Invoke(null, new object[] { guids, _exportSettings.OutputFilename });
|
||||
method?.Invoke(null, new object[] { guids, _legacyExportSettings.OutputFilename });
|
||||
|
||||
// The internal exporter methods are asynchronous, therefore
|
||||
// we need to wait for exporting to finish before returning
|
||||
await Task.Run(() =>
|
||||
{
|
||||
while (!File.Exists(_exportSettings.OutputFilename))
|
||||
while (!File.Exists(_legacyExportSettings.OutputFilename))
|
||||
Thread.Sleep(100);
|
||||
});
|
||||
|
||||
ASDebug.Log($"Package file has been created at {_exportSettings.OutputFilename}");
|
||||
return new ExportResult() { Success = true, ExportedPath = _exportSettings.OutputFilename };
|
||||
ASDebug.Log($"Package file has been created at {_legacyExportSettings.OutputFilename}");
|
||||
return new PackageExporterResult() { Success = true, ExportedPath = _legacyExportSettings.OutputFilename };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ExportResult() { Success = false, Error = ASError.GetGenericError(e) };
|
||||
return new PackageExporterResult() { Success = false, Exception = e };
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/PackageExporterLegacy.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/LegacyPackageExporter.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,13 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using System;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class PackageExporterResult
|
||||
{
|
||||
public bool Success;
|
||||
public string ExportedPath;
|
||||
public PreviewGenerationResult PreviewGenerationResult;
|
||||
public Exception Exception;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce99a618d1e211444b53f18bb3444f75
|
||||
guid: e685b1c322eab4540919d4fc970e812d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/ExportResult.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/PackageExporterResult.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,41 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace AssetStoreTools.Exporter
|
||||
{
|
||||
internal class PreviewInjector : IPreviewInjector
|
||||
{
|
||||
private PreviewGenerationResult _result;
|
||||
|
||||
public PreviewInjector(PreviewGenerationResult result)
|
||||
{
|
||||
_result = result;
|
||||
}
|
||||
|
||||
public void Inject(string temporaryPackagePath)
|
||||
{
|
||||
if (_result == null || !_result.Success)
|
||||
return;
|
||||
|
||||
var previews = _result.Previews.Where(x => x.Type == _result.GenerationType && x.Exists());
|
||||
InjectFilesIntoGuidFolders(previews, temporaryPackagePath);
|
||||
}
|
||||
|
||||
private void InjectFilesIntoGuidFolders(IEnumerable<PreviewMetadata> previews, string temporaryPackagePath)
|
||||
{
|
||||
foreach (var assetFolder in Directory.EnumerateDirectories(temporaryPackagePath))
|
||||
{
|
||||
var guid = assetFolder.Replace("\\", "/").Split('/').Last();
|
||||
var generatedPreview = previews.FirstOrDefault(x => x.Guid.Equals(guid));
|
||||
|
||||
if (generatedPreview == null)
|
||||
continue;
|
||||
|
||||
// Note: Unity Importer and Asset Store only operate with .png extensions
|
||||
File.Copy(generatedPreview.Path, $"{assetFolder}/preview.png", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52ef11a59e545544fafaa99a5fa6cce9
|
||||
guid: 772db784128e32d4792bb680258c71df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/PackageExporter.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Exporter/PreviewInjector.cs
|
||||
uploadId: 724584
|
||||
Reference in New Issue
Block a user