update libs
This commit is contained in:
@@ -1,6 +1,37 @@
|
||||
# Changelog
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [12.0.1] - 2025-01-16
|
||||
|
||||
### Preview Generator changes
|
||||
- Updated generated preview collection UI to display the asset extension
|
||||
- Fixed an issue with some prefab and model asset types not generating previews
|
||||
- Fixed an error that could occur when changing scenes after deleting a preview source asset
|
||||
|
||||
## [12.0.0] - 2025-01-13
|
||||
|
||||
### General changes
|
||||
- The code comprising the Asset Store Publishing Tools has been refactored.
|
||||
- Added dependency on Newtonsoft Json
|
||||
|
||||
### Uploader changes
|
||||
- Updated window to retain its state if closed unless a domain reload occurs
|
||||
- Added option to generate higher resolution asset previews when exporting
|
||||
- Fixed a rare issue where authentication would fail
|
||||
- Minor UI tweaks
|
||||
|
||||
### Validator changes
|
||||
- Added validation tests for:
|
||||
- Package naming
|
||||
- Project Template assets
|
||||
- Updated the Type Namespace validation test to check for Unity top level namespaces
|
||||
|
||||
### Exporter changes
|
||||
- Updated how asset previews are generated/included for the package that is being exported
|
||||
|
||||
### Preview Generator
|
||||
- Added a Preview Generator window that can be used to pre-generate and inspect package previews before exporting
|
||||
|
||||
## [11.4.4] - 2024-11-29
|
||||
|
||||
### Validator Changes
|
||||
|
||||
@@ -9,6 +9,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/CHANGELOG.md
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3eb6991a3db8cc34dad63504bc6c3c0e
|
||||
guid: d48a2325d352e7a4cae56d3f8eeaab2d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6e2d6bcfe000764e9330d78017e32bc
|
||||
guid: 25799fb31cd475347af7f5442c231797
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,48 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using AssetStoreTools.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal abstract class AuthenticationBase : IAuthenticationType
|
||||
{
|
||||
protected Uri LoginUrl = ApiUtility.CreateUri(Constants.Api.AuthenticateUrl, true);
|
||||
protected FormUrlEncodedContent AuthenticationContent;
|
||||
|
||||
protected FormUrlEncodedContent GetAuthenticationContent(params KeyValuePair<string, string>[] content)
|
||||
{
|
||||
var baseContent = Constants.Api.DefaultAssetStoreQuery();
|
||||
|
||||
try { baseContent.Add("license_hash", ApiUtility.GetLicenseHash()); } catch { ASDebug.LogWarning("Could not retrieve license hash"); }
|
||||
try { baseContent.Add("hardware_hash", ApiUtility.GetHardwareHash()); } catch { ASDebug.LogWarning("Could not retrieve hardware hash"); }
|
||||
|
||||
foreach (var extraContent in content)
|
||||
{
|
||||
baseContent.Add(extraContent.Key, extraContent.Value);
|
||||
}
|
||||
|
||||
return new FormUrlEncodedContent(baseContent);
|
||||
}
|
||||
|
||||
protected AuthenticationResponse ParseResponse(HttpResponseMessage response)
|
||||
{
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
var responseString = response.Content.ReadAsStringAsync().Result;
|
||||
return new AuthenticationResponse(responseString);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
return new AuthenticationResponse(response.StatusCode, e) { Success = false };
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Task<AuthenticationResponse> Authenticate(IAssetStoreClient client, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f677e03f1be1048439a1fa5e7a0a37b6
|
||||
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/Api/Abstractions/AuthenticationBase.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,21 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal interface IAssetStoreApi
|
||||
{
|
||||
Task<AssetStoreToolsVersionResponse> GetLatestAssetStoreToolsVersion(CancellationToken cancellationToken = default);
|
||||
Task<AuthenticationResponse> Authenticate(IAuthenticationType authenticationType, CancellationToken cancellationToken = default);
|
||||
void Deauthenticate();
|
||||
Task<PackagesDataResponse> GetPackages(CancellationToken cancellationToken = default);
|
||||
Task<CategoryDataResponse> GetCategories(CancellationToken cancellationToken = default);
|
||||
Task<PackageThumbnailResponse> GetPackageThumbnail(Package package, CancellationToken cancellationToken = default);
|
||||
Task<RefreshedPackageDataResponse> RefreshPackageMetadata(Package package, CancellationToken cancellationToken = default);
|
||||
Task<PackageUploadedUnityVersionDataResponse> GetPackageUploadedVersions(Package package, CancellationToken cancellationToken = default);
|
||||
Task<PackageUploadResponse> UploadPackage(IPackageUploader uploader, IProgress<float> progress = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e616488c25d278741bb0d08168219309
|
||||
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/Api/Abstractions/IAssetStoreApi.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal interface IAssetStoreClient
|
||||
{
|
||||
void SetSessionId(string sessionId);
|
||||
void ClearSessionId();
|
||||
|
||||
Task<HttpResponseMessage> Get(Uri uri, CancellationToken cancellationToken = default);
|
||||
Task<HttpResponseMessage> Post(Uri uri, HttpContent content, CancellationToken cancellationToken = default);
|
||||
Task<HttpResponseMessage> Put(Uri uri, HttpContent content, CancellationToken cancellationToken = default);
|
||||
Task<HttpResponseMessage> Send(HttpRequestMessage request, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2bbadec62178cc4189e605367b219e7
|
||||
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/Api/Abstractions/IAssetStoreClient.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,11 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal interface IAuthenticationType
|
||||
{
|
||||
Task<AuthenticationResponse> Authenticate(IAssetStoreClient client, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0000dcd6975bc8e4abc546a19f194040
|
||||
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/Api/Abstractions/IAuthenticationType.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,12 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal interface IPackageUploader
|
||||
{
|
||||
Task<PackageUploadResponse> Upload(IAssetStoreClient client, IProgress<float> progress, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fc6c47b1c0a65540a40efbf1491193b
|
||||
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/Api/Abstractions/IPackageUploader.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,59 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal abstract class PackageUploaderBase : IPackageUploader
|
||||
{
|
||||
protected const int UploadChunkSizeBytes = 32768;
|
||||
protected const int UploadResponseTimeoutMs = 10000;
|
||||
|
||||
protected abstract void ValidateSettings();
|
||||
public abstract Task<PackageUploadResponse> Upload(IAssetStoreClient client, IProgress<float> progress = null, CancellationToken cancellationToken = default);
|
||||
|
||||
protected void EnsureSuccessResponse(HttpResponseMessage response)
|
||||
{
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception(response.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
}
|
||||
|
||||
protected void WaitForUploadCompletion(Task<HttpResponseMessage> response, FileStream requestFileStream, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
// Progress tracking
|
||||
int updateIntervalMs = 100;
|
||||
bool allBytesSent = false;
|
||||
DateTime timeOfCompletion = default;
|
||||
|
||||
while (!response.IsCompleted)
|
||||
{
|
||||
float uploadProgress = (float)requestFileStream.Position / requestFileStream.Length * 100;
|
||||
progress?.Report(uploadProgress);
|
||||
Thread.Sleep(updateIntervalMs);
|
||||
|
||||
// A timeout for rare cases, when package uploading reaches 100%, but Put task IsComplete value remains 'False'
|
||||
if (requestFileStream.Position == requestFileStream.Length)
|
||||
{
|
||||
if (!allBytesSent)
|
||||
{
|
||||
allBytesSent = true;
|
||||
timeOfCompletion = DateTime.UtcNow;
|
||||
}
|
||||
else if (DateTime.UtcNow.Subtract(timeOfCompletion).TotalMilliseconds > UploadResponseTimeoutMs)
|
||||
{
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2718ddd16e425ba4a82ab973724bcff7
|
||||
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/Api/Abstractions/PackageUploaderBase.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,76 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using AssetStoreTools.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class ApiUtility
|
||||
{
|
||||
public static Uri CreateUri(string url, bool includeDefaultAssetStoreQuery) => CreateUri(url, null, includeDefaultAssetStoreQuery);
|
||||
public static Uri CreateUri(string url, IDictionary<string, string> queryParameters, bool includeDefaultAssetStoreQuery)
|
||||
{
|
||||
IDictionary<string, string> fullQueryParameters = includeDefaultAssetStoreQuery ?
|
||||
Constants.Api.DefaultAssetStoreQuery() : new Dictionary<string, string>();
|
||||
|
||||
if (queryParameters != null && queryParameters.Count > 0)
|
||||
{
|
||||
foreach (var kvp in queryParameters)
|
||||
fullQueryParameters.Add(kvp);
|
||||
}
|
||||
|
||||
var builder = new UriBuilder(url);
|
||||
if (fullQueryParameters.Count == 0)
|
||||
return builder.Uri;
|
||||
|
||||
var fullQueryParameterString = string.Empty;
|
||||
foreach (var queryParam in fullQueryParameters)
|
||||
{
|
||||
var escapedValue = queryParam.Value != null ? Uri.EscapeDataString(queryParam.Value) : string.Empty;
|
||||
fullQueryParameterString += $"{queryParam.Key}={escapedValue}&";
|
||||
}
|
||||
fullQueryParameterString = fullQueryParameterString.Remove(fullQueryParameterString.Length - 1);
|
||||
|
||||
builder.Query = fullQueryParameterString;
|
||||
return builder.Uri;
|
||||
}
|
||||
|
||||
public static List<Package> CombinePackageData(List<Package> mainPackageData, List<PackageAdditionalData> extraPackageData, List<Category> categoryData)
|
||||
{
|
||||
foreach (var package in mainPackageData)
|
||||
{
|
||||
var extraData = extraPackageData.FirstOrDefault(x => package.PackageId == x.PackageId);
|
||||
|
||||
if (extraData == null)
|
||||
{
|
||||
ASDebug.LogWarning($"Could not find extra data for Package {package.PackageId}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var categoryId = extraData.CategoryId;
|
||||
var category = categoryData.FirstOrDefault(x => x.Id.ToString() == categoryId);
|
||||
if (category != null)
|
||||
package.Category = category.Name;
|
||||
else
|
||||
package.Category = "Unknown";
|
||||
|
||||
package.Modified = extraData.Modified;
|
||||
package.Size = extraData.Size;
|
||||
}
|
||||
|
||||
return mainPackageData;
|
||||
}
|
||||
|
||||
public static string GetLicenseHash()
|
||||
{
|
||||
return InternalEditorUtility.GetAuthToken().Substring(0, 40);
|
||||
}
|
||||
|
||||
public static string GetHardwareHash()
|
||||
{
|
||||
return InternalEditorUtility.GetAuthToken().Substring(40, 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5becec0b3c0ba274fb0b01544e63b6c4
|
||||
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/Api/ApiUtility.cs
|
||||
uploadId: 724584
|
||||
268
Packages/com.unity.asset-store-tools/Editor/Api/AssetStoreApi.cs
Normal file
268
Packages/com.unity.asset-store-tools/Editor/Api/AssetStoreApi.cs
Normal file
@@ -0,0 +1,268 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class AssetStoreApi : IAssetStoreApi
|
||||
{
|
||||
private IAssetStoreClient _client;
|
||||
|
||||
public AssetStoreApi(IAssetStoreClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task<AssetStoreToolsVersionResponse> GetLatestAssetStoreToolsVersion(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = ApiUtility.CreateUri(Constants.Api.AssetStoreToolsLatestVersionUrl, false);
|
||||
var response = await _client.Get(uri, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
var responseStr = response.Content.ReadAsStringAsync().Result;
|
||||
return new AssetStoreToolsVersionResponse(responseStr);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new AssetStoreToolsVersionResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new AssetStoreToolsVersionResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<AuthenticationResponse> Authenticate(IAuthenticationType authenticationType, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var loginResponse = await authenticationType.Authenticate(_client, cancellationToken);
|
||||
if (loginResponse.Success)
|
||||
{
|
||||
_client.SetSessionId(loginResponse.User.SessionId);
|
||||
}
|
||||
|
||||
return loginResponse;
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new AuthenticationResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new AuthenticationResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public void Deauthenticate()
|
||||
{
|
||||
_client.ClearSessionId();
|
||||
}
|
||||
|
||||
public async Task<PackagesDataResponse> GetPackages(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var mainDataResponse = await GetPackageDataMain(cancellationToken);
|
||||
if (!mainDataResponse.Success)
|
||||
throw mainDataResponse.Exception;
|
||||
var additionalDataResponse = await GetPackageDataExtra(cancellationToken);
|
||||
if (!additionalDataResponse.Success)
|
||||
throw additionalDataResponse.Exception;
|
||||
var categoryDataResponse = await GetCategories(cancellationToken);
|
||||
if (!categoryDataResponse.Success)
|
||||
throw categoryDataResponse.Exception;
|
||||
|
||||
var joinedData = ApiUtility.CombinePackageData(mainDataResponse.Packages, additionalDataResponse.Packages, categoryDataResponse.Categories);
|
||||
return new PackagesDataResponse() { Success = true, Packages = joinedData };
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackagesDataResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackagesDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<PackagesDataResponse> GetPackageDataMain(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = ApiUtility.CreateUri(Constants.Api.GetPackagesUrl, true);
|
||||
var response = await _client.Get(uri, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseStr = response.Content.ReadAsStringAsync().Result;
|
||||
return new PackagesDataResponse(responseStr);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackagesDataResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackagesDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<PackagesAdditionalDataResponse> GetPackageDataExtra(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = ApiUtility.CreateUri(Constants.Api.GetPackagesAdditionalDataUrl, true);
|
||||
var response = await _client.Get(uri, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseStr = response.Content.ReadAsStringAsync().Result;
|
||||
return new PackagesAdditionalDataResponse(responseStr);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackagesAdditionalDataResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackagesAdditionalDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CategoryDataResponse> GetCategories(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = ApiUtility.CreateUri(Constants.Api.GetCategoriesUrl, true);
|
||||
var response = await _client.Get(uri, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseStr = response.Content.ReadAsStringAsync().Result;
|
||||
return new CategoryDataResponse(responseStr);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new CategoryDataResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new CategoryDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PackageThumbnailResponse> GetPackageThumbnail(Package package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(package.IconUrl))
|
||||
throw new Exception($"Could not retrieve thumbnail for package {package.PackageId} - icon url is null");
|
||||
|
||||
var response = await _client.Get(new Uri(package.IconUrl), cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseBytes = response.Content.ReadAsByteArrayAsync().Result;
|
||||
return new PackageThumbnailResponse(responseBytes);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackageThumbnailResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageThumbnailResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<RefreshedPackageDataResponse> RefreshPackageMetadata(Package package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var refreshedPackage = JObject.FromObject(package).DeepClone().ToObject<Package>();
|
||||
|
||||
var packagesResponse = await GetPackageDataExtra(cancellationToken);
|
||||
if (!packagesResponse.Success)
|
||||
throw packagesResponse.Exception;
|
||||
|
||||
// Find the updated package data in the latest data json
|
||||
var packageRefreshSource = packagesResponse.Packages.FirstOrDefault(x => x.PackageId == refreshedPackage.PackageId);
|
||||
if (packageRefreshSource == null)
|
||||
return new RefreshedPackageDataResponse() { Success = false, Exception = new MissingMemberException($"Unable to find downloaded package data for package id {package.PackageId}") };
|
||||
|
||||
// Retrieve the category map
|
||||
var categoryData = await GetCategories(cancellationToken);
|
||||
if (!categoryData.Success)
|
||||
return new RefreshedPackageDataResponse() { Success = false, Exception = packagesResponse.Exception };
|
||||
|
||||
// Update the package data
|
||||
refreshedPackage.Name = packageRefreshSource.Name;
|
||||
refreshedPackage.Status = packageRefreshSource.Status;
|
||||
var newCategory = categoryData.Categories.FirstOrDefault(x => x.Id.ToString() == packageRefreshSource.CategoryId);
|
||||
refreshedPackage.Category = newCategory != null ? newCategory.Name : "Unknown";
|
||||
refreshedPackage.Modified = packageRefreshSource.Modified;
|
||||
refreshedPackage.Size = packageRefreshSource.Size;
|
||||
|
||||
return new RefreshedPackageDataResponse() { Success = true, Package = refreshedPackage };
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return new RefreshedPackageDataResponse() { Success = false, Cancelled = true };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new RefreshedPackageDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PackageUploadedUnityVersionDataResponse> GetPackageUploadedVersions(Package package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = ApiUtility.CreateUri(Constants.Api.GetPackageUploadedVersionsUrl(package.PackageId, package.VersionId), true);
|
||||
var response = await _client.Get(uri, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseStr = response.Content.ReadAsStringAsync().Result;
|
||||
return new PackageUploadedUnityVersionDataResponse(responseStr);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackageUploadedUnityVersionDataResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageUploadedUnityVersionDataResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PackageUploadResponse> UploadPackage(IPackageUploader uploader, IProgress<float> progress = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await uploader.Upload(_client, progress, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = false, Cancelled = true, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = false, Exception = e };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 684fca3fffd79d944a32d9b3adbfc007
|
||||
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/Api/AssetStoreApi.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class AssetStoreClient : IAssetStoreClient
|
||||
{
|
||||
private HttpClient _httpClient;
|
||||
|
||||
public AssetStoreClient()
|
||||
{
|
||||
ServicePointManager.DefaultConnectionLimit = 500;
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.ConnectionClose = false;
|
||||
_httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
_httpClient.Timeout = TimeSpan.FromMinutes(1320);
|
||||
}
|
||||
|
||||
public void SetSessionId(string sessionId)
|
||||
{
|
||||
ClearSessionId();
|
||||
|
||||
if (!string.IsNullOrEmpty(sessionId))
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Unity-Session", sessionId);
|
||||
}
|
||||
|
||||
public void ClearSessionId()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Remove("X-Unity-Session");
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> Get(Uri uri, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _httpClient.GetAsync(uri, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> Post(Uri uri, HttpContent content, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _httpClient.PostAsync(uri, content, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> Put(Uri uri, HttpContent content, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _httpClient.PutAsync(uri, content, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> Send(HttpRequestMessage request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _httpClient.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80b4527c908161a4b9f06dc393b502f9
|
||||
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/Api/AssetStoreClient.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,25 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class CloudTokenAuthentication : AuthenticationBase
|
||||
{
|
||||
public CloudTokenAuthentication(string cloudToken)
|
||||
{
|
||||
AuthenticationContent = GetAuthenticationContent(
|
||||
new KeyValuePair<string, string>("user_access_token", cloudToken)
|
||||
);
|
||||
}
|
||||
|
||||
public override async Task<AuthenticationResponse> Authenticate(IAssetStoreClient client, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await client.Post(LoginUrl, AuthenticationContent, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return ParseResponse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99f1baec74f26a34bb972b19c92d523f
|
||||
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/Api/CloudTokenAuthentication.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,26 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class CredentialsAuthentication : AuthenticationBase
|
||||
{
|
||||
public CredentialsAuthentication(string email, string password)
|
||||
{
|
||||
AuthenticationContent = GetAuthenticationContent(
|
||||
new KeyValuePair<string, string>("user", email),
|
||||
new KeyValuePair<string, string>("pass", password)
|
||||
);
|
||||
}
|
||||
|
||||
public override async Task<AuthenticationResponse> Authenticate(IAssetStoreClient client, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await client.Post(LoginUrl, AuthenticationContent, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return ParseResponse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 353e556b63fd441428f387bc85aa612c
|
||||
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/Api/CredentialsAuthentication.cs
|
||||
uploadId: 724584
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 854f6f9e93b37204eb2e6042138643bc
|
||||
guid: 1f83e4b5507886f4b873c22c146b8f6a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Models
|
||||
{
|
||||
internal class Category
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Status { get; set; }
|
||||
|
||||
public class AssetStoreCategoryResolver : DefaultContractResolver
|
||||
{
|
||||
private Dictionary<string, string> _propertyConversions;
|
||||
|
||||
public AssetStoreCategoryResolver()
|
||||
{
|
||||
_propertyConversions = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(Category.Name), "assetstore_name" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversions.ContainsKey(propertyName))
|
||||
return _propertyConversions[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedCategoryResolver : DefaultContractResolver
|
||||
{
|
||||
private static CachedCategoryResolver _instance;
|
||||
public static CachedCategoryResolver Instance => _instance ?? (_instance = new CachedCategoryResolver());
|
||||
|
||||
private Dictionary<string, string> _propertyConversion;
|
||||
|
||||
private CachedCategoryResolver()
|
||||
{
|
||||
this.NamingStrategy = new SnakeCaseNamingStrategy();
|
||||
_propertyConversion = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(Category.Name), "name" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversion.ContainsKey(propertyName))
|
||||
return _propertyConversion[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5897866bc65f5834dab1f17371daada7
|
||||
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/Api/Models/Category.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,80 @@
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Models
|
||||
{
|
||||
internal class Package
|
||||
{
|
||||
public string PackageId { get; set; }
|
||||
public string VersionId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Status { get; set; }
|
||||
public string Category { get; set; }
|
||||
public bool IsCompleteProject { get; set; }
|
||||
public string RootGuid { get; set; }
|
||||
public string RootPath { get; set; }
|
||||
public string ProjectPath { get; set; }
|
||||
public string Modified { get; set; }
|
||||
public string Size { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
|
||||
public class AssetStorePackageResolver : DefaultContractResolver
|
||||
{
|
||||
private static AssetStorePackageResolver _instance;
|
||||
public static AssetStorePackageResolver Instance => _instance ?? (_instance = new AssetStorePackageResolver());
|
||||
|
||||
private Dictionary<string, string> _propertyConversions;
|
||||
|
||||
private AssetStorePackageResolver()
|
||||
{
|
||||
_propertyConversions = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(Package.VersionId), "id" },
|
||||
{ nameof(Package.IsCompleteProject), "is_complete_project" },
|
||||
{ nameof(Package.RootGuid), "root_guid" },
|
||||
{ nameof(Package.RootPath), "root_path" },
|
||||
{ nameof(Package.ProjectPath), "project_path" },
|
||||
{ nameof(Package.IconUrl), "icon_url" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversions.ContainsKey(propertyName))
|
||||
return _propertyConversions[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public class CachedPackageResolver : DefaultContractResolver
|
||||
{
|
||||
private static CachedPackageResolver _instance;
|
||||
public static CachedPackageResolver Instance => _instance ?? (_instance = new CachedPackageResolver());
|
||||
|
||||
private Dictionary<string, string> _propertyConversion;
|
||||
|
||||
private CachedPackageResolver()
|
||||
{
|
||||
this.NamingStrategy = new SnakeCaseNamingStrategy();
|
||||
_propertyConversion = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(Package.PackageId), "package_id" },
|
||||
{ nameof(Package.VersionId), "version_id" },
|
||||
{ nameof(Package.IsCompleteProject), "is_complete_project" },
|
||||
{ nameof(Package.RootGuid), "root_guid" },
|
||||
{ nameof(Package.RootPath), "root_path" },
|
||||
{ nameof(Package.IconUrl), "icon_url" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversion.ContainsKey(propertyName))
|
||||
return _propertyConversion[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e9f0b99820061b49abf6e8cf544a727
|
||||
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/Api/Models/Package.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,41 @@
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Models
|
||||
{
|
||||
internal class PackageAdditionalData
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Status { get; set; }
|
||||
public string PackageId { get; set; }
|
||||
public string VersionId { get; set; }
|
||||
public string CategoryId { get; set; }
|
||||
public string Modified { get; set; }
|
||||
public string Size { get; set; }
|
||||
|
||||
public class AssetStorePackageResolver : DefaultContractResolver
|
||||
{
|
||||
private static AssetStorePackageResolver _instance;
|
||||
public static AssetStorePackageResolver Instance => _instance ?? (_instance = new AssetStorePackageResolver());
|
||||
|
||||
private Dictionary<string, string> _propertyConversions;
|
||||
|
||||
private AssetStorePackageResolver()
|
||||
{
|
||||
_propertyConversions = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(PackageAdditionalData.PackageId), "id" },
|
||||
{ nameof(PackageAdditionalData.CategoryId), "category_id" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversions.ContainsKey(propertyName))
|
||||
return _propertyConversions[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0663f29f3fcd0e34ab77338d1bdbb528
|
||||
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/Api/Models/PackageAdditionalData.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,51 @@
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Models
|
||||
{
|
||||
internal class User
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string SessionId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string PublisherId { get; set; }
|
||||
public bool IsPublisher => !string.IsNullOrEmpty(PublisherId);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return
|
||||
$"{nameof(Id)}: {Id}\n" +
|
||||
$"{nameof(Name)}: {Name}\n" +
|
||||
$"{nameof(Username)}: {Username}\n" +
|
||||
$"{nameof(PublisherId)}: {PublisherId}\n" +
|
||||
$"{nameof(IsPublisher)}: {IsPublisher}\n" +
|
||||
$"{nameof(SessionId)}: [HIDDEN]";
|
||||
}
|
||||
|
||||
public class AssetStoreUserResolver : DefaultContractResolver
|
||||
{
|
||||
private static AssetStoreUserResolver _instance;
|
||||
public static AssetStoreUserResolver Instance => _instance ?? (_instance = new AssetStoreUserResolver());
|
||||
|
||||
private Dictionary<string, string> _propertyConversions;
|
||||
|
||||
private AssetStoreUserResolver()
|
||||
{
|
||||
_propertyConversions = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(User.SessionId), "xunitysession" },
|
||||
{ nameof(User.PublisherId), "publisher" }
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
if (_propertyConversions.ContainsKey(propertyName))
|
||||
return _propertyConversions[propertyName];
|
||||
|
||||
return base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: caf38df5cd685a345a1ebec8f7651c93
|
||||
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/Api/Models/User.cs
|
||||
uploadId: 724584
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c85e58f7d4786a40a140c67b0d124a0
|
||||
guid: 49581213e7b6ca645955cce8ce23ac4b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to return the success outcome and the result of Asset Store API calls
|
||||
/// </summary>
|
||||
internal class AssetStoreResponse
|
||||
{
|
||||
public bool Success { get; set; } = false;
|
||||
public bool Cancelled { get; set; } = false;
|
||||
public Exception Exception { get; set; }
|
||||
|
||||
public AssetStoreResponse() { }
|
||||
|
||||
public AssetStoreResponse(Exception e) : this()
|
||||
{
|
||||
Exception = e;
|
||||
}
|
||||
|
||||
protected void ValidateAssetStoreResponse(string json)
|
||||
{
|
||||
var dict = JsonConvert.DeserializeObject<JObject>(json);
|
||||
if (dict == null)
|
||||
throw new Exception("Response is empty");
|
||||
|
||||
// Some json responses return an error field on error
|
||||
if (dict.ContainsKey("error"))
|
||||
{
|
||||
// Server side error message
|
||||
// Do not write to console since this is an error that
|
||||
// is "expected" ie. can be handled by the gui.
|
||||
throw new Exception(dict.GetValue("error").ToString());
|
||||
}
|
||||
// Some json responses return status+message fields instead of an error field. Go figure.
|
||||
else if (dict.ContainsKey("status") && dict.GetValue("status").ToString() != "ok"
|
||||
&& dict.ContainsKey("message"))
|
||||
{
|
||||
throw new Exception(dict.GetValue("message").ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee338db031a0cfb459f7cac7f41a5d75
|
||||
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/Api/Responses/AssetStoreResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,38 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class AssetStoreToolsVersionResponse : AssetStoreResponse
|
||||
{
|
||||
public string Version { get; set; }
|
||||
|
||||
public AssetStoreToolsVersionResponse() : base() { }
|
||||
public AssetStoreToolsVersionResponse(Exception e) : base(e) { }
|
||||
|
||||
public AssetStoreToolsVersionResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
ParseVersion(json);
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseVersion(string json)
|
||||
{
|
||||
var dict = JsonConvert.DeserializeObject<JObject>(json);
|
||||
if (!dict.ContainsKey("version"))
|
||||
throw new Exception("Version was not found");
|
||||
|
||||
Version = dict.GetValue("version").ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40558675926f913478a654350149209e
|
||||
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/Api/Responses/AssetStoreToolsVersionResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,74 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class AuthenticationResponse : AssetStoreResponse
|
||||
{
|
||||
public User User { get; set; }
|
||||
|
||||
public AuthenticationResponse() : base() { }
|
||||
|
||||
public AuthenticationResponse(Exception e) : base(e) { }
|
||||
|
||||
public AuthenticationResponse(HttpStatusCode statusCode, HttpRequestException fallbackException)
|
||||
{
|
||||
string message;
|
||||
switch (statusCode)
|
||||
{
|
||||
case HttpStatusCode.Unauthorized:
|
||||
message = "Incorrect email and/or password. Please try again.";
|
||||
break;
|
||||
case HttpStatusCode.InternalServerError:
|
||||
message = "Authentication request failed\nIf you were logging in with your Unity Cloud account, please make sure you are still logged in.\n" +
|
||||
"This might also be caused by too many invalid login attempts - if that is the case, please try again later.";
|
||||
break;
|
||||
default:
|
||||
Exception = fallbackException;
|
||||
return;
|
||||
}
|
||||
|
||||
Exception = new Exception(message);
|
||||
}
|
||||
|
||||
public AuthenticationResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
var serializerSettings = new JsonSerializerSettings()
|
||||
{
|
||||
ContractResolver = User.AssetStoreUserResolver.Instance
|
||||
};
|
||||
User = JsonConvert.DeserializeObject<User>(json, serializerSettings);
|
||||
ValidateLoginData();
|
||||
ValidatePublisher();
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateLoginData()
|
||||
{
|
||||
if (string.IsNullOrEmpty(User.Id)
|
||||
|| string.IsNullOrEmpty(User.SessionId)
|
||||
|| string.IsNullOrEmpty(User.Name)
|
||||
|| string.IsNullOrEmpty(User.Username))
|
||||
throw new Exception("Could not parse the necessary publisher information from the response.");
|
||||
}
|
||||
|
||||
private void ValidatePublisher()
|
||||
{
|
||||
if (!User.IsPublisher)
|
||||
throw new Exception($"Your Unity ID {User.Name} is not currently connected to a publisher account. " +
|
||||
$"Please create a publisher profile.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec3a5cb59a7e78646b07f800d317874d
|
||||
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/Api/Responses/AuthenticationResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,43 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class CategoryDataResponse : AssetStoreResponse
|
||||
{
|
||||
public List<Category> Categories { get; set; }
|
||||
|
||||
public CategoryDataResponse() : base() { }
|
||||
public CategoryDataResponse(Exception e) : base(e) { }
|
||||
|
||||
public CategoryDataResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var categoryArray = JsonConvert.DeserializeObject<JArray>(json);
|
||||
|
||||
Categories = new List<Category>();
|
||||
var serializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new Category.AssetStoreCategoryResolver()
|
||||
};
|
||||
|
||||
foreach (var categoryData in categoryArray)
|
||||
{
|
||||
var category = categoryData.ToObject<Category>(serializer);
|
||||
Categories.Add(category);
|
||||
}
|
||||
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3789323453f1604286b436f77bdca97
|
||||
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/Api/Responses/CategoryDataResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class PackageThumbnailResponse : AssetStoreResponse
|
||||
{
|
||||
public Texture2D Thumbnail { get; set; }
|
||||
public PackageThumbnailResponse() : base() { }
|
||||
public PackageThumbnailResponse(Exception e) : base(e) { }
|
||||
|
||||
public PackageThumbnailResponse(byte[] textureBytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
|
||||
var success = tex.LoadImage(textureBytes);
|
||||
if (!success)
|
||||
throw new Exception("Could not retrieve image from the provided texture bytes");
|
||||
|
||||
Thumbnail = tex;
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dacfba636b3757e408514b850d715e18
|
||||
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/Api/Responses/PackageThumbnailResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,44 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class PackageUploadedUnityVersionDataResponse : AssetStoreResponse
|
||||
{
|
||||
public List<string> UnityVersions { get; set; }
|
||||
|
||||
public PackageUploadedUnityVersionDataResponse() : base() { }
|
||||
public PackageUploadedUnityVersionDataResponse(Exception e) : base(e) { }
|
||||
|
||||
public PackageUploadedUnityVersionDataResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
ParseVersionData(json);
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseVersionData(string json)
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject<JObject>(json);
|
||||
try
|
||||
{
|
||||
var content = data.GetValue("content").ToObject<JObject>();
|
||||
UnityVersions = content.GetValue("unity_versions").ToObject<List<string>>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception("Could not parse the unity versions array");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2552f659a600e124aa952f3ba760ddf3
|
||||
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/Api/Responses/PackageUploadedUnityVersionDataResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,59 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class PackagesAdditionalDataResponse : AssetStoreResponse
|
||||
{
|
||||
public List<PackageAdditionalData> Packages { get; set; }
|
||||
|
||||
public PackagesAdditionalDataResponse() : base() { }
|
||||
public PackagesAdditionalDataResponse(Exception e) : base(e) { }
|
||||
|
||||
public PackagesAdditionalDataResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
ParseExtraData(json);
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseExtraData(string json)
|
||||
{
|
||||
var packageDict = JsonConvert.DeserializeObject<JObject>(json);
|
||||
if (!packageDict.ContainsKey("packages"))
|
||||
throw new Exception("Response did not not contain the list of packages");
|
||||
|
||||
Packages = new List<PackageAdditionalData>();
|
||||
var serializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = PackageAdditionalData.AssetStorePackageResolver.Instance
|
||||
};
|
||||
|
||||
var packageArray = packageDict.GetValue("packages").ToObject<JArray>();
|
||||
foreach (var packageData in packageArray)
|
||||
{
|
||||
var package = packageData.ToObject<PackageAdditionalData>(serializer);
|
||||
|
||||
// Some fields are based on the latest version in the json
|
||||
var latestVersion = packageData["versions"].ToObject<JArray>().Last;
|
||||
|
||||
package.VersionId = latestVersion["id"].ToString();
|
||||
package.Modified = latestVersion["modified"].ToString();
|
||||
package.Size = latestVersion["size"].ToString();
|
||||
|
||||
Packages.Add(package);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88d58ad5e0eea6345b5c83f30ee8ebd5
|
||||
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/Api/Responses/PackagesAdditionalDataResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,59 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class PackagesDataResponse : AssetStoreResponse
|
||||
{
|
||||
public List<Package> Packages { get; set; }
|
||||
|
||||
public PackagesDataResponse() : base() { }
|
||||
public PackagesDataResponse(Exception e) : base(e) { }
|
||||
|
||||
public PackagesDataResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
ParseMainData(json);
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseMainData(string json)
|
||||
{
|
||||
var packageDict = JsonConvert.DeserializeObject<JObject>(json);
|
||||
if (!packageDict.ContainsKey("packages"))
|
||||
throw new Exception("Response did not not contain the list of packages");
|
||||
|
||||
Packages = new List<Package>();
|
||||
var serializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = Package.AssetStorePackageResolver.Instance
|
||||
};
|
||||
|
||||
foreach (var packageToken in packageDict["packages"])
|
||||
{
|
||||
var property = (JProperty)packageToken;
|
||||
var packageData = property.Value.ToObject<Package>(serializer);
|
||||
|
||||
// Package Id is the key of the package object
|
||||
packageData.PackageId = property.Name;
|
||||
|
||||
// Package Icon Url is returned without the https: prefix
|
||||
if (!string.IsNullOrEmpty(packageData.IconUrl))
|
||||
packageData.IconUrl = $"https:{packageData.IconUrl}";
|
||||
|
||||
Packages.Add(packageData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 705ec748e689148479f54666993cd79d
|
||||
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/Api/Responses/PackagesDataResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,12 @@
|
||||
using AssetStoreTools.Api.Models;
|
||||
using System;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class RefreshedPackageDataResponse : AssetStoreResponse
|
||||
{
|
||||
public Package Package { get; set; }
|
||||
public RefreshedPackageDataResponse() { }
|
||||
public RefreshedPackageDataResponse(Exception e) : base(e) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20f710024d5ed514db02672f12ac361c
|
||||
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/Api/Responses/RefreshedPackageDataResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace AssetStoreTools.Api.Responses
|
||||
{
|
||||
internal class PackageUploadResponse : AssetStoreResponse
|
||||
{
|
||||
public UploadStatus Status { get; set; }
|
||||
|
||||
public PackageUploadResponse() : base() { }
|
||||
public PackageUploadResponse(Exception e) : base(e) { }
|
||||
|
||||
public PackageUploadResponse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateAssetStoreResponse(json);
|
||||
Status = UploadStatus.Success;
|
||||
Success = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Success = false;
|
||||
Status = UploadStatus.Fail;
|
||||
Exception = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f1758cfa8119cf49a61b010a04352e4
|
||||
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/Api/Responses/UploadResponse.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,25 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class SessionAuthentication : AuthenticationBase
|
||||
{
|
||||
public SessionAuthentication(string sessionId)
|
||||
{
|
||||
AuthenticationContent = GetAuthenticationContent(
|
||||
new KeyValuePair<string, string>("reuse_session", sessionId)
|
||||
);
|
||||
}
|
||||
|
||||
public override async Task<AuthenticationResponse> Authenticate(IAssetStoreClient client, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await client.Post(LoginUrl, AuthenticationContent, cancellationToken);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
return ParseResponse(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02e970f660088cc4b89003608d59cd06
|
||||
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/Api/SessionAuthentication.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,99 @@
|
||||
using AssetStoreTools.Api.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal class UnityPackageUploadSettings
|
||||
{
|
||||
public string VersionId { get; set; }
|
||||
public string UnityPackagePath { get; set; }
|
||||
public string RootGuid { get; set; }
|
||||
public string RootPath { get; set; }
|
||||
public string ProjectPath { get; set; }
|
||||
}
|
||||
|
||||
internal class UnityPackageUploader : PackageUploaderBase
|
||||
{
|
||||
private UnityPackageUploadSettings _settings;
|
||||
private Uri _uploadUri;
|
||||
|
||||
public UnityPackageUploader(UnityPackageUploadSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
protected override void ValidateSettings()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_settings.VersionId))
|
||||
throw new Exception("Version Id is unset");
|
||||
|
||||
if (string.IsNullOrEmpty(_settings.UnityPackagePath)
|
||||
|| !File.Exists(_settings.UnityPackagePath))
|
||||
throw new Exception("Package file could not be found");
|
||||
|
||||
if (!_settings.UnityPackagePath.EndsWith(".unitypackage"))
|
||||
throw new Exception("Provided package file is not .unitypackage");
|
||||
}
|
||||
|
||||
public override async Task<PackageUploadResponse> Upload(IAssetStoreClient client, IProgress<float> progress = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateSettings();
|
||||
|
||||
var endpoint = Constants.Api.UploadUnityPackageUrl(_settings.VersionId);
|
||||
var query = new Dictionary<string, string>()
|
||||
{
|
||||
{ "root_guid", _settings.RootGuid },
|
||||
{ "root_path", _settings.RootPath },
|
||||
{ "project_path", _settings.ProjectPath }
|
||||
};
|
||||
|
||||
_uploadUri = ApiUtility.CreateUri(endpoint, query, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = false, Status = UploadStatus.Fail, Exception = e };
|
||||
}
|
||||
|
||||
return await Task.Run(() => UploadTask(client, progress, cancellationToken));
|
||||
}
|
||||
|
||||
private PackageUploadResponse UploadTask(IAssetStoreClient client, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream requestFileStream = new FileStream(_settings.UnityPackagePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var content = new StreamContent(requestFileStream, UploadChunkSizeBytes);
|
||||
|
||||
var response = client.Put(_uploadUri, content, cancellationToken);
|
||||
WaitForUploadCompletion(response, requestFileStream, progress, cancellationToken);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
EnsureSuccessResponse(response.Result);
|
||||
|
||||
var responseStr = response.Result.Content.ReadAsStringAsync().Result;
|
||||
return new PackageUploadResponse(responseStr);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = false, Cancelled = true, Status = UploadStatus.Cancelled, Exception = e };
|
||||
}
|
||||
catch (TimeoutException e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = true, Status = UploadStatus.ResponseTimeout, Exception = e };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageUploadResponse() { Success = false, Exception = e, Status = UploadStatus.Fail };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95bd0284375397f41a2065e07d4ba526
|
||||
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/Api/UnityPackageUploader.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AssetStoreTools.Api
|
||||
{
|
||||
internal enum UploadStatus
|
||||
{
|
||||
Default = 0,
|
||||
Success = 1,
|
||||
Fail = 2,
|
||||
Cancelled = 3,
|
||||
ResponseTimeout = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a121831a941cb64a8a9d21ca6fda9c3
|
||||
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/Api/UploadStatus.cs
|
||||
uploadId: 724584
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
[assembly: InternalsVisibleTo("Unity.AssetStoreTools.Editor.Tests.asmdef")]
|
||||
[assembly: InternalsVisibleTo("AssetStoreTools.Tests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
[assembly: InternalsVisibleTo("ab-builder")]
|
||||
[assembly: InternalsVisibleTo("Inspector-Editor")]
|
||||
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/AssemblyInfo.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -1,31 +1,53 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using AssetStoreTools.Previews.UI;
|
||||
using AssetStoreTools.Uploader;
|
||||
using AssetStoreTools.Utility;
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using AssetStoreTools.Validator.UI;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using AssetStoreTools.Uploader;
|
||||
using AssetStoreTools.Validator;
|
||||
using AssetStoreTools.Utility;
|
||||
|
||||
namespace AssetStoreTools
|
||||
{
|
||||
internal class AssetStoreTools : EditorWindow
|
||||
internal static class AssetStoreTools
|
||||
{
|
||||
[MenuItem("Tools/Asset Store/Uploader", false, 0)]
|
||||
public static void ShowAssetStoreToolsUploader()
|
||||
{
|
||||
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
|
||||
var wnd = GetWindow<AssetStoreUploader>(inspectorType);
|
||||
var wnd = EditorWindow.GetWindow<UploaderWindow>(inspectorType);
|
||||
wnd.Show();
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Tools/Asset Store/Validator", false, 1)]
|
||||
public static void ShowAssetStoreToolsValidator()
|
||||
{
|
||||
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
|
||||
var wnd = GetWindow<AssetStoreValidator>(typeof(AssetStoreUploader), inspectorType);
|
||||
var wnd = EditorWindow.GetWindow<ValidatorWindow>(typeof(UploaderWindow), inspectorType);
|
||||
wnd.Show();
|
||||
}
|
||||
|
||||
public static void ShowAssetStoreToolsValidator(ValidationSettings settings, ValidationResult result)
|
||||
{
|
||||
ShowAssetStoreToolsValidator();
|
||||
EditorWindow.GetWindow<ValidatorWindow>().Load(settings, result);
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Asset Store/Preview Generator", false, 2)]
|
||||
public static void ShowAssetStoreToolsPreviewGenerator()
|
||||
{
|
||||
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
|
||||
var wnd = EditorWindow.GetWindow<PreviewGeneratorWindow>(inspectorType);
|
||||
wnd.Show();
|
||||
}
|
||||
|
||||
public static void ShowAssetStoreToolsPreviewGenerator(PreviewGenerationSettings settings)
|
||||
{
|
||||
ShowAssetStoreToolsPreviewGenerator();
|
||||
EditorWindow.GetWindow<PreviewGeneratorWindow>().Load(settings);
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Asset Store/Publisher Portal", false, 20)]
|
||||
public static void OpenPublisherPortal()
|
||||
{
|
||||
@@ -47,7 +69,7 @@ namespace AssetStoreTools
|
||||
[MenuItem("Tools/Asset Store/Check for Updates", false, 45)]
|
||||
public static void OpenUpdateChecker()
|
||||
{
|
||||
var wnd = GetWindowWithRect<ASToolsUpdater>(new Rect(Screen.width / 2, Screen.height / 2, 400, 150), true);
|
||||
var wnd = EditorWindow.GetWindowWithRect<ASToolsUpdater>(new Rect(Screen.width / 2, Screen.height / 2, 400, 150), true);
|
||||
wnd.Show();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/AssetStoreTools.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -7,15 +7,17 @@ namespace AssetStoreTools
|
||||
{
|
||||
protected abstract string WindowTitle { get; }
|
||||
|
||||
protected virtual void Init()
|
||||
private void DefaultInit()
|
||||
{
|
||||
titleContent = new GUIContent(WindowTitle);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
protected abstract void Init();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
DefaultInit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/AssetStoreToolsWindow.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
178
Packages/com.unity.asset-store-tools/Editor/Constants.cs
Normal file
178
Packages/com.unity.asset-store-tools/Editor/Constants.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using AssetStoreTools.Previews.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
|
||||
|
||||
namespace AssetStoreTools
|
||||
{
|
||||
internal class Constants
|
||||
{
|
||||
#if UNITY_EDITOR_OSX
|
||||
public static readonly string UnityPath = System.IO.Path.Combine(EditorApplication.applicationPath, "Contents", "MacOS", "Unity");
|
||||
#else
|
||||
public static readonly string UnityPath = EditorApplication.applicationPath;
|
||||
#endif
|
||||
public static readonly string RootProjectPath = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length);
|
||||
|
||||
private static bool GetArgument(string argumentName, out string argumentValue)
|
||||
{
|
||||
argumentValue = string.Empty;
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (!args[i].Equals(argumentName, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
if (i + 1 >= args.Length)
|
||||
return false;
|
||||
|
||||
argumentValue = args[i + 1];
|
||||
break;
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(argumentValue);
|
||||
}
|
||||
|
||||
public class Api
|
||||
{
|
||||
public static readonly string ApiVersion = $"V{PackageInfo.FindForAssetPath("Packages/com.unity.asset-store-tools").version}";
|
||||
public const string AssetStoreToolsLatestVersionUrl = "https://api.assetstore.unity3d.com/package/latest-version/115";
|
||||
|
||||
private const string AssetStoreBaseUrlDefault = "https://kharma.unity3d.com";
|
||||
private const string AssetStoreBaseUrlOverrideArgument = "-assetStoreUrl";
|
||||
public static readonly string AssetStoreBaseUrl = !GetArgument(AssetStoreBaseUrlOverrideArgument, out var overriddenUrl)
|
||||
? AssetStoreBaseUrlDefault
|
||||
: overriddenUrl;
|
||||
|
||||
public static readonly string AuthenticateUrl = $"{AssetStoreBaseUrl}/login";
|
||||
public static readonly string GetPackagesUrl = $"{AssetStoreBaseUrl}/api/asset-store-tools/metadata/0.json";
|
||||
public static readonly string GetPackagesAdditionalDataUrl = $"{AssetStoreBaseUrl}/api/management/packages.json";
|
||||
public static readonly string GetCategoriesUrl = $"{AssetStoreBaseUrl}/api/management/categories.json";
|
||||
|
||||
public static string GetPackageUploadedVersionsUrl(string packageId, string versionId) =>
|
||||
$"{AssetStoreBaseUrl}/api/content/preview/{packageId}/{versionId}.json";
|
||||
public static string UploadUnityPackageUrl(string versionId) =>
|
||||
$"{AssetStoreBaseUrl}/api/asset-store-tools/package/{versionId}/unitypackage.json";
|
||||
|
||||
public static IDictionary<string, string> DefaultAssetStoreQuery()
|
||||
{
|
||||
var dict = new Dictionary<string, string>()
|
||||
{
|
||||
{ "unityversion", Application.unityVersion },
|
||||
{ "toolversion", ApiVersion }
|
||||
};
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
public class Updater
|
||||
{
|
||||
public const string AssetStoreToolsUrl = "https://assetstore.unity.com/packages/tools/utilities/asset-store-publishing-tools-115";
|
||||
}
|
||||
|
||||
public class Cache
|
||||
{
|
||||
public const string SessionTokenKey = "kharma.sessionid";
|
||||
public const string TempCachePath = "Temp/AssetStoreToolsCache";
|
||||
public const string PersistentCachePath = "Library/AssetStoreToolsCache";
|
||||
|
||||
public const string PackageDataFileName = "PackageMetadata.json";
|
||||
public const string CategoryDataFile = "Categories.json";
|
||||
public const string ValidationResultFile = "ValidationStateData.asset";
|
||||
|
||||
public static string PackageThumbnailFileName(string packageId) => $"{packageId}.png";
|
||||
public static string WorkflowStateDataFileName(string packageId) => $"{packageId}-workflowStateData.asset";
|
||||
}
|
||||
|
||||
public class Uploader
|
||||
{
|
||||
public const string MinRequiredUnitySupportVersion = "2021.3";
|
||||
public const long MaxPackageSizeBytes = 6576668672; // 6 GB + 128MB of headroom
|
||||
public const string AccountRegistrationUrl = "https://publisher.unity.com/access";
|
||||
public const string AccountForgottenPasswordUrl = "https://id.unity.com/password/new";
|
||||
|
||||
public class Analytics
|
||||
{
|
||||
public const string VendorKey = "unity.assetStoreTools";
|
||||
public const int MaxEventsPerHour = 20;
|
||||
public const int MaxNumberOfElements = 1000;
|
||||
|
||||
public class AuthenticationAnalytics
|
||||
{
|
||||
public const string EventName = "assetStoreToolsLogin";
|
||||
public const int EventVersion = 1;
|
||||
}
|
||||
|
||||
public class PackageUploadAnalytics
|
||||
{
|
||||
public const string EventName = "assetStoreTools";
|
||||
public const int EventVersion = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Validator
|
||||
{
|
||||
public const string SubmissionGuidelinesUrl = "https://assetstore.unity.com/publishing/submission-guidelines#Overview";
|
||||
public const string SupportTicketUrl = "https://support.unity.com/hc/en-us/requests/new?ticket_form_id=65905";
|
||||
|
||||
public class Tests
|
||||
{
|
||||
public const string TestDefinitionsPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Tests";
|
||||
public const string TestMethodsPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Methods";
|
||||
|
||||
public static readonly string GenericTestMethodsPath = $"{TestMethodsPath}/Generic";
|
||||
public static readonly string UnityPackageTestMethodsPath = $"{TestMethodsPath}/UnityPackage";
|
||||
}
|
||||
}
|
||||
|
||||
public class Previews
|
||||
{
|
||||
public const string PreviewDatabaseFile = "PreviewDatabase.json";
|
||||
|
||||
public static readonly string DefaultOutputPath = $"{Cache.TempCachePath}/AssetPreviews";
|
||||
public const FileNameFormat DefaultFileNameFormat = FileNameFormat.Guid;
|
||||
|
||||
public class Native
|
||||
{
|
||||
public static readonly string DefaultOutputPath = $"{Previews.DefaultOutputPath}/Native";
|
||||
public const PreviewFormat DefaultFormat = PreviewFormat.PNG;
|
||||
public const bool DefaultWaitForPreviews = true;
|
||||
public const bool DefaultChunkedPreviewLoading = true;
|
||||
public const int DefaultChunkSize = 100;
|
||||
}
|
||||
|
||||
public class Custom
|
||||
{
|
||||
public static readonly string DefaultOutputPath = $"{Previews.DefaultOutputPath}/Custom";
|
||||
public const PreviewFormat DefaultFormat = PreviewFormat.JPG;
|
||||
public const int DefaultWidth = 300;
|
||||
public const int DefaultHeight = 300;
|
||||
public const int DefaultDepth = 32;
|
||||
|
||||
public const int DefaultNativeWidth = 900;
|
||||
public const int DefaultNativeHeight = 900;
|
||||
|
||||
public static readonly Color DefaultAudioSampleColor = new Color(1f, 0.55f, 0);
|
||||
public static readonly Color DefaultAudioBackgroundColor = new Color(0.32f, 0.32f, 0.32f);
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowStyles
|
||||
{
|
||||
public const string UploaderStylesPath = "Packages/com.unity.asset-store-tools/Editor/Uploader/Styles";
|
||||
public const string ValidatorStylesPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Styles";
|
||||
public const string ValidatorIconsPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Icons";
|
||||
public const string PreviewGeneratorStylesPath = "Packages/com.unity.asset-store-tools/Editor/Previews/Styles";
|
||||
public const string UpdaterStylesPath = "Packages/com.unity.asset-store-tools/Editor/Utility/Styles/Updater";
|
||||
}
|
||||
|
||||
public class Debug
|
||||
{
|
||||
public const string DebugModeKey = "ASTDebugMode";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4ee1f78505bda748ae24b3dfd2606ca
|
||||
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/Constants.cs
|
||||
uploadId: 724584
|
||||
@@ -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,46 +8,50 @@ 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) };
|
||||
|
||||
switch (exportSettings)
|
||||
{
|
||||
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")) };
|
||||
}
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
private static bool IsSettingsValid(ExporterSettings settings, out Exception e)
|
||||
public async Task<PackageExporterResult> Export()
|
||||
{
|
||||
e = 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");
|
||||
|
||||
return e == null;
|
||||
try
|
||||
{
|
||||
ValidateSettings();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new PackageExporterResult() { Success = false, Exception = e };
|
||||
}
|
||||
|
||||
return await ExportImpl();
|
||||
}
|
||||
|
||||
protected virtual void ValidateSettings()
|
||||
{
|
||||
if (Settings == null)
|
||||
throw new ArgumentException("Settings cannot be null");
|
||||
|
||||
if (string.IsNullOrEmpty(Settings.OutputFilename))
|
||||
throw new ArgumentException("Output path cannot be 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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
var obj = kvp.Value;
|
||||
var queuePreview = false;
|
||||
if (_defaultExportSettings.PreviewGenerator == null)
|
||||
return null;
|
||||
|
||||
switch (obj)
|
||||
void ReportProgress(float progress)
|
||||
{
|
||||
case Material _:
|
||||
case TerrainLayer _:
|
||||
case AudioClip _:
|
||||
case Mesh _:
|
||||
case Texture _:
|
||||
case UnityEngine.Tilemaps.Tile _:
|
||||
case GameObject _:
|
||||
queuePreview = true;
|
||||
break;
|
||||
EditorUtility.DisplayProgressBar(ProgressBarTitle, ProgressBarStepGeneratingPreviews, progress);
|
||||
}
|
||||
|
||||
if (!queuePreview)
|
||||
continue;
|
||||
_defaultExportSettings.PreviewGenerator.OnProgressChanged += ReportProgress;
|
||||
var result = await _defaultExportSettings.PreviewGenerator.Generate();
|
||||
_defaultExportSettings.PreviewGenerator.OnProgressChanged -= ReportProgress;
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
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)
|
||||
if (!result.Success)
|
||||
{
|
||||
File.WriteAllBytes(kvp.Key + "/preview.png", bytes);
|
||||
UnityEngine.Debug.LogWarning($"An error was encountered while generating previews. Exported package may be missing previews.\n{result.Exception}");
|
||||
}
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt);
|
||||
}
|
||||
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
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13e8cd63112e52d43a7e65949f0143a4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbe1aebea6551424997b361fab69f266
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae99e2e3b5a83d1469110306c96f4c58
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Previews.Data
|
||||
{
|
||||
internal class CustomPreviewGenerationSettings : PreviewGenerationSettings
|
||||
{
|
||||
public override GenerationType GenerationType => GenerationType.Custom;
|
||||
|
||||
public int Width;
|
||||
public int Height;
|
||||
public int Depth;
|
||||
|
||||
public int NativeWidth;
|
||||
public int NativeHeight;
|
||||
|
||||
public Color AudioSampleColor;
|
||||
public Color AudioBackgroundColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ccb1292c1c4ba94cb6f4022ecfdfa50
|
||||
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/Previews/Scripts/Data/CustomPreviewGenerationSettings.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AssetStoreTools.Previews.Data
|
||||
{
|
||||
internal enum FileNameFormat
|
||||
{
|
||||
Guid = 0,
|
||||
FullAssetPath = 1,
|
||||
AssetName = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38a1babecfeaf524f98e8d67882acf48
|
||||
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/Previews/Scripts/Data/FileNameFormat.cs
|
||||
uploadId: 724584
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user