Skip to content

PreviewAssetManager

ClassAssetInventoryAssetInventory.Editor
public static class PreviewAssetManager

Asset materialization and dependency management for preview generation. Extracted from PreviewManager to separate concerns.

MaterializePackageFilesAsync(List, DependencyResultCache, bool, Action<string, int, int>, Func)

Section titled “MaterializePackageFilesAsync(List, DependencyResultCache, bool, Action<string, int, int>, Func)”
public static Task<Dictionary<int, string>> MaterializePackageFilesAsync(List<AssetInfo> files, DependencyResultCache cache, bool selectiveMode = false, Action<string, int, int> onProgress = null, Func<bool> isCancelled = null)

Materializes all files and their dependencies in a single batch operation.

NEW FLOW (dramatically reduces refreshes):

  1. Get ALL non-script files from the package
  2. Bulk import them to preview work folder - ONE refresh (files become YAML)
  3. Store paths in cache so dependency analysis can find them
  4. Run dependency analysis - now finds in-project files, skips temp folder dance
  5. Materialize any cross-package dependencies

Parameters

Name Type Description
files System.Collections.Generic.List{AssetInventory.AssetInfo} Files to materialize
cache AssetInventory.DependencyResultCache Cache for dependency memoization and materialized path storage
selectiveMode System.Boolean When true, only imports dependency-needing file types (prefabs, materials, FBX, shaders, etc.) and their discovered dependencies. Non-dependency files (images, audio, video) are left for per-file handling. This avoids importing thousands of files that don’t need Unity’s import pipeline for preview generation.
onProgress System.Action{System.String,System.Int32,System.Int32} Optional progress callback (message, current, total). Called between batches during dependency analysis to update progress bars.
isCancelled System.Func{System.Boolean} Optional cancellation check. Return true to abort processing.

Returns

System.Threading.Tasks.Task{System.Collections.Generic.Dictionary{System.Int32,System.String}} — Dictionary mapping AssetInfo.Id to materialized project-relative path

EnsureDependenciesAsync(AssetInfo, string, DependencyResultCache)

Section titled “EnsureDependenciesAsync(AssetInfo, string, DependencyResultCache)”
public static Task<string> EnsureDependenciesAsync(AssetInfo info, string sourcePath, DependencyResultCache cache = null)

Ensure all dependencies for an asset are materialized before preview generation

Parameters

Name Type Description
info AssetInventory.AssetInfo
sourcePath System.String
cache AssetInventory.DependencyResultCache

Returns

System.Threading.Tasks.Task{System.String} — No return description is available.

public static string DerivePreviewFile(string sourcePath)

Derive the preview file path from a source asset path

Parameters

Name Type Description
sourcePath System.String

Returns

System.String — No return description is available.