update libs

This commit is contained in:
Kirill Chikalin
2025-02-13 17:48:12 +03:00
parent e17e7c2786
commit 275dc598c7
816 changed files with 22479 additions and 10792 deletions

View File

@@ -0,0 +1,56 @@
using AssetStoreTools.Previews.Data;
using System;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace AssetStoreTools.Previews.UI.Data
{
internal class AssetPreview : IAssetPreview
{
private PreviewMetadata _metadata;
private UnityEngine.Object _cachedAsset;
private string _cachedAssetPath;
private Texture2D _cachedTexture;
public UnityEngine.Object Asset => _cachedAsset ?? (_cachedAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(AssetPath));
public string AssetPath => _cachedAssetPath ?? (_cachedAssetPath = AssetDatabase.GUIDToAssetPath(_metadata.Guid));
public AssetPreview(PreviewMetadata metadata)
{
_metadata = metadata;
}
public string GetAssetPath()
{
var assetPath = AssetDatabase.GUIDToAssetPath(_metadata.Guid);
return assetPath;
}
public async Task LoadImage(Action<Texture2D> onSuccess)
{
if (_cachedTexture == null)
{
if (!_metadata.Exists())
return;
await Task.Yield();
try
{
_cachedTexture = new Texture2D(1, 1);
_cachedTexture.LoadImage(File.ReadAllBytes(_metadata.Path));
}
catch (Exception e)
{
Debug.LogException(e);
return;
}
}
onSuccess?.Invoke(_cachedTexture);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 739cf05c689204f4089fd0a6bddb8c3b
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/UI/Data/AssetPreview.cs
uploadId: 724584

View File

@@ -0,0 +1,46 @@
using AssetStoreTools.Previews.Data;
using System;
using System.Collections.Generic;
namespace AssetStoreTools.Previews.UI.Data
{
internal class AssetPreviewCollection : IAssetPreviewCollection
{
private GenerationType _generationType;
private List<IAssetPreview> _images;
public event Action OnCollectionChanged;
public AssetPreviewCollection()
{
_images = new List<IAssetPreview>();
}
public GenerationType GetGenerationType()
{
return _generationType;
}
public IEnumerable<IAssetPreview> GetPreviews()
{
return _images;
}
public void Refresh(GenerationType generationType, IEnumerable<PreviewMetadata> previews)
{
_images.Clear();
_generationType = generationType;
foreach (var entry in previews)
{
if (!entry.Exists())
continue;
_images.Add(new AssetPreview(entry));
}
OnCollectionChanged?.Invoke();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9b1a0db8710933048b49dcca463fb8fd
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/UI/Data/AssetPreviewCollection.cs
uploadId: 724584

View File

@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace AssetStoreTools.Previews.UI.Data
{
internal interface IAssetPreview
{
UnityEngine.Object Asset { get; }
string GetAssetPath();
Task LoadImage(Action<Texture2D> onSuccess);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0f9373dfc16d0fa4794dac29b75204ec
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/UI/Data/IAssetPreview.cs
uploadId: 724584

View File

@@ -0,0 +1,15 @@
using AssetStoreTools.Previews.Data;
using System;
using System.Collections.Generic;
namespace AssetStoreTools.Previews.UI.Data
{
internal interface IAssetPreviewCollection
{
event Action OnCollectionChanged;
GenerationType GetGenerationType();
IEnumerable<IAssetPreview> GetPreviews();
void Refresh(GenerationType generationType, IEnumerable<PreviewMetadata> previews);
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: fc9d9abd80c070f44ac49d5ce23d2fc0
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/UI/Data/IAssetPreviewCollection.cs
uploadId: 724584

View File

@@ -0,0 +1,27 @@
using AssetStoreTools.Previews.Data;
using AssetStoreTools.Previews.Generators;
using System;
using System.Collections.Generic;
namespace AssetStoreTools.Previews.UI.Data
{
internal interface IPreviewGeneratorSettings
{
event Action OnGenerationTypeChanged;
event Action OnGenerationPathsChanged;
void LoadSettings(PreviewGenerationSettings settings);
GenerationType GetGenerationType();
void SetGenerationType(GenerationType type);
List<GenerationType> GetAvailableGenerationTypes();
List<string> GetGenerationPaths();
void AddGenerationPath(string path);
void RemoveGenerationPath(string path);
void ClearGenerationPaths();
bool IsGenerationPathValid(string path, out string error);
IPreviewGenerator CreateGenerator();
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 55c9fcde15f06754588fd02fb8b99a60
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/UI/Data/IPreviewGeneratorSettings.cs
uploadId: 724584

View File

@@ -0,0 +1,212 @@
using AssetStoreTools.Previews.Data;
using AssetStoreTools.Previews.Generators;
using AssetStoreTools.Utility;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace AssetStoreTools.Previews.UI.Data
{
internal class PreviewGeneratorSettings : IPreviewGeneratorSettings
{
private readonly GenerationType[] _availableGenerationTypes = new GenerationType[]
{
GenerationType.Native,
GenerationType.Custom
};
private List<string> _inputPaths;
private GenerationType _generationType;
public event Action OnGenerationTypeChanged;
public event Action OnGenerationPathsChanged;
public PreviewGeneratorSettings()
{
_inputPaths = new List<string>();
_generationType = GenerationType.Native;
}
public void LoadSettings(PreviewGenerationSettings settings)
{
if (settings == null)
return;
_inputPaths = settings.InputPaths.ToList();
OnGenerationPathsChanged?.Invoke();
switch (settings)
{
case NativePreviewGenerationSettings _:
_generationType = GenerationType.Native;
break;
case CustomPreviewGenerationSettings _:
_generationType = GenerationType.Custom;
break;
default:
return;
}
OnGenerationTypeChanged?.Invoke();
}
public GenerationType GetGenerationType()
{
return _generationType;
}
public void SetGenerationType(GenerationType type)
{
_generationType = type;
OnGenerationTypeChanged?.Invoke();
}
public List<GenerationType> GetAvailableGenerationTypes()
{
return _availableGenerationTypes.ToList();
}
public List<string> GetGenerationPaths()
{
return _inputPaths;
}
public void AddGenerationPath(string path)
{
if (string.IsNullOrEmpty(path))
return;
if (_inputPaths.Contains(path))
return;
// Prevent redundancy for new paths
var existingPath = _inputPaths.FirstOrDefault(x => path.StartsWith(x + "/"));
if (existingPath != null)
{
Debug.LogWarning($"Path '{path}' is already included with existing path: '{existingPath}'");
return;
}
// Prevent redundancy for already added paths
var redundantPaths = _inputPaths.Where(x => x.StartsWith(path + "/")).ToArray();
foreach (var redundantPath in redundantPaths)
{
Debug.LogWarning($"Existing validation path '{redundantPath}' has been made redundant by the inclusion of new validation path: '{path}'");
_inputPaths.Remove(redundantPath);
}
_inputPaths.Add(path);
OnGenerationPathsChanged?.Invoke();
}
public void RemoveGenerationPath(string path)
{
if (!_inputPaths.Contains(path))
return;
_inputPaths.Remove(path);
OnGenerationPathsChanged?.Invoke();
}
public void ClearGenerationPaths()
{
if (_inputPaths.Count == 0)
return;
_inputPaths.Clear();
OnGenerationPathsChanged?.Invoke();
}
public bool IsGenerationPathValid(string path, out string error)
{
error = string.Empty;
if (string.IsNullOrEmpty(path))
{
error = "Path cannot be empty";
return false;
}
var isAssetsPath = path.StartsWith("Assets/")
|| path.Equals("Assets");
var isPackagePath = PackageUtility.GetPackageByManifestPath($"{path}/package.json", out _);
if (!isAssetsPath && !isPackagePath)
{
error = "Selected path must be within the Assets folder or point to a root path of a package";
return false;
}
if (!Directory.Exists(path))
{
error = "Path does not exist";
return false;
}
if (path.Split('/').Any(x => x.StartsWith(".") || x.EndsWith("~")))
{
error = $"Path '{path}' cannot be selected as it is a hidden folder and not part of the Asset Database";
return false;
}
return true;
}
public IPreviewGenerator CreateGenerator()
{
switch (_generationType)
{
case GenerationType.Native:
return CreateNativeGenerator();
case GenerationType.Custom:
return CreateCustomGenerator();
default:
throw new NotImplementedException("Undefined generator type");
}
}
private IPreviewGenerator CreateNativeGenerator()
{
var settings = new NativePreviewGenerationSettings()
{
InputPaths = _inputPaths.ToArray(),
OutputPath = Constants.Previews.Native.DefaultOutputPath,
PreviewFileNamingFormat = Constants.Previews.DefaultFileNameFormat,
Format = Constants.Previews.Native.DefaultFormat,
WaitForPreviews = Constants.Previews.Native.DefaultWaitForPreviews,
ChunkedPreviewLoading = Constants.Previews.Native.DefaultChunkedPreviewLoading,
ChunkSize = Constants.Previews.Native.DefaultChunkSize,
OverwriteExisting = true
};
return new NativePreviewGenerator(settings);
}
private IPreviewGenerator CreateCustomGenerator()
{
var settings = new CustomPreviewGenerationSettings()
{
InputPaths = _inputPaths.ToArray(),
OutputPath = Constants.Previews.Custom.DefaultOutputPath,
Width = Constants.Previews.Custom.DefaultWidth,
Height = Constants.Previews.Custom.DefaultHeight,
Depth = Constants.Previews.Custom.DefaultDepth,
NativeWidth = Constants.Previews.Custom.DefaultNativeWidth,
NativeHeight = Constants.Previews.Custom.DefaultNativeHeight,
PreviewFileNamingFormat = Constants.Previews.DefaultFileNameFormat,
Format = Constants.Previews.Custom.DefaultFormat,
AudioSampleColor = Constants.Previews.Custom.DefaultAudioSampleColor,
AudioBackgroundColor = Constants.Previews.Custom.DefaultAudioBackgroundColor,
OverwriteExisting = true
};
var generator = new CustomPreviewGenerator(settings);
return generator;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9e6f754b1179d8d4cb40f62692619a63
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/UI/Data/PreviewGeneratorSettings.cs
uploadId: 724584