Improve AssetDatabase performance.
This commit is contained in:
@@ -2,21 +2,16 @@ using Ghost.Core;
|
||||
|
||||
namespace Ghost.Editor.Core.AssetHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all asset importers.
|
||||
/// Asset importers process source files and convert them into engine-ready formats.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSettings">The type of importer settings this importer uses.</typeparam>
|
||||
internal abstract class AssetImporter<TSettings>
|
||||
where TSettings : ImporterSettings, new()
|
||||
public abstract class AssetImporter
|
||||
{
|
||||
/// <summary>
|
||||
/// Import the asset at the specified path with the given settings.
|
||||
/// </summary>
|
||||
/// <param name="assetPath">Full path to the source asset file.</param>
|
||||
/// <param name="meta">Metadata for the asset.</param>
|
||||
/// <param name="token">Cancellation token.</param>
|
||||
/// <returns>Result indicating success or failure.</returns>
|
||||
public abstract Task<Result> ImportAsync(string assetPath, AssetMeta meta);
|
||||
public abstract ValueTask<Result> ImportAsync(string assetPath, AssetMeta meta, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Export in-memory asset data to disk.
|
||||
@@ -26,31 +21,12 @@ internal abstract class AssetImporter<TSettings>
|
||||
/// <param name="assetPath">Full path where the asset should be saved.</param>
|
||||
/// <param name="assetData">In-memory asset data to serialize.</param>
|
||||
/// <param name="meta">Metadata for the asset.</param>
|
||||
/// <param name="token">Cancellation token.</param>
|
||||
/// <returns>Result indicating success or failure.</returns>
|
||||
public virtual Task<Result> ExportAsync<T>(string assetPath, T assetData, AssetMeta meta) where T : class
|
||||
public virtual ValueTask<Result> ExportAsync<T>(string assetPath, T assetData, AssetMeta meta, CancellationToken token = default)
|
||||
where T : class
|
||||
{
|
||||
return Task.FromResult(Result.Failure("This importer does not support exporting assets."));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the settings for this importer from the metadata.
|
||||
/// Creates default settings if none exist.
|
||||
/// </summary>
|
||||
/// <param name="meta">Asset metadata.</param>
|
||||
/// <returns>The importer settings.</returns>
|
||||
protected TSettings GetSettings(AssetMeta meta)
|
||||
{
|
||||
var typeName = GetType().Name;
|
||||
var settings = meta.GetImporterSettings<TSettings>(typeName);
|
||||
|
||||
if (settings != null)
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
||||
var defaultSettings = new TSettings();
|
||||
meta.SetImporterSettings(typeName, defaultSettings);
|
||||
return defaultSettings;
|
||||
return ValueTask.FromResult(Result.Failure("This importer does not support exporting assets."));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,3 +54,28 @@ internal abstract class AssetImporter<TSettings>
|
||||
return ValueTask.FromResult(Result.Success());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AssetImporter<TSettings> : AssetImporter
|
||||
where TSettings : ImporterSettings, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the settings for this importer from the metadata.
|
||||
/// Creates default settings if none exist.
|
||||
/// </summary>
|
||||
/// <param name="meta">Asset metadata.</param>
|
||||
/// <returns>The importer settings.</returns>
|
||||
protected TSettings GetSettings(AssetMeta meta)
|
||||
{
|
||||
var typeName = GetType().Name;
|
||||
var settings = meta.GetImporterSettings<TSettings>(typeName);
|
||||
|
||||
if (settings != null)
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
||||
var defaultSettings = new TSettings();
|
||||
meta.SetImporterSettings(typeName, defaultSettings);
|
||||
return defaultSettings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user