AssetDatabase
- Namespace: Turian.Engine.Core
- Source File: AssetDatabase.Paths.cs, AssetDatabase.Registration.cs, AssetDatabase.cs, AssetDatabase.Catalog.cs
Properties
Instance
(AssetDatabase): Gets the singleton instance of the AssetDatabase.
Assets
(Dictionary<Guid, AssetRecord>) { get; set } = []: Gets the indexed asset records keyed by asset identifier.
Public Methods
RegisterAssetFromMetaFile
public bool RegisterAssetFromMetaFile(string metaFilePath, string? importedPrimaryContentPath = null)
Registers or updates an asset entry using a meta file path.
Parameters:
metaFilePath(string): The absolute meta file path.importedPrimaryContentPath(string?): Optional absolute imported payload path. (Default:null)
Returns: bool
trueif the asset was registered; otherwise,false.
RemoveAsset
public bool RemoveAsset(Guid assetId)
Removes an asset from the database by its identifier.
Parameters:
assetId(Guid): The asset identifier.
Returns: bool
trueif the asset existed and was removed; otherwise,false.
RemoveAssetFromMetaFile
public bool RemoveAssetFromMetaFile(string metaFilePath)
Removes an asset from the database using a meta file path.
Parameters:
metaFilePath(string): The absolute meta file path.
Returns: bool
trueif the asset existed and was removed; otherwise,false.
MoveAsset
public void MoveAsset(Guid assetId, string newSourcePath, string? newImportedPrimaryContentPath = null)
Updates an asset's source path and optional imported content path.
Parameters:
assetId(Guid): The asset identifier.newSourcePath(string): The new absolute source path.newImportedPrimaryContentPath(string?): Optional absolute imported payload path. (Default:null)
MoveAssetFromMetaFile
public bool MoveAssetFromMetaFile(string metaFilePath, string? importedPrimaryContentPath = null)
Updates an asset's path information using a meta file path.
Parameters:
metaFilePath(string): The absolute meta file path.importedPrimaryContentPath(string?): Optional absolute imported payload path. (Default:null)
Returns: bool
trueif the asset was updated; otherwise,false.
TryGetAsset
public bool TryGetAsset(Guid assetId, AssetRecord? record)
Attempts to get a registered asset record.
Parameters:
assetId(Guid): The asset identifier.record(AssetRecord?): The resolved record.
Returns: bool
trueif the asset exists; otherwise,false.
TryGetAssetProvider
public bool TryGetAssetProvider(Guid assetId, IAssetFileProvider? provider)
Attempts to get a file provider for the asset's primary content. Supports both loose imported files and packed runtime content.
Parameters:
assetId(Guid): The asset identifier.provider(IAssetFileProvider?): The resolved provider.
Returns: bool
trueif the provider could be created; otherwise,false.
GetAssetsSnapshot
public IReadOnlyCollection<AssetRecord> GetAssetsSnapshot()
Gets a snapshot of all indexed asset records.
Returns: IReadOnlyCollection<AssetRecord>
- A read-only snapshot of asset records.
UpdateComponentTypes
public bool UpdateComponentTypes(Guid assetId, IReadOnlyCollection<string> componentTypes)
Updates the cached list of component type names carried by the asset's content. Only meaningful for prefab-like assets; callers pass the fully-qualified names of every Component instance found in the prefab hierarchy.
Parameters:
assetId(Guid): The asset identifier.componentTypes(IReadOnlyCollection): The component type names to store.
Returns: bool
trueif the record was updated; otherwisefalse.
MergeDatabase
public void MergeDatabase(Dictionary<Guid, AssetRecord>? assetsNew)
Merges the provided assets into the database.
Parameters:
assetsNew(Dictionary<Guid, AssetRecord>?): The asset records to merge.
TryGetInstance
public static bool TryGetInstance(AssetDatabase? database)
Gets the singleton instance if one has been created, without throwing. For callers that run both inside a loaded project and standalone (the UI compositor, driven by code-built panels in headless demos and by document assets in a project).
Parameters:
database(AssetDatabase?): The instance, ornullwhen no project is loaded.
Returns: bool
truewhen an instance exists.
BuildDatabase
public void BuildDatabase(string assetFolderPath, bool recursive = true)
Builds the database for a project by scanning source metadata under the project's Assets folder and merging it with the persisted cache catalog when available.
Parameters:
assetFolderPath(string): The absolute path to the project'sAssetsdirectory.recursive(bool): Whether metadata files should be discovered recursively. (Default:true)
LoadCatalogFromProject
public AssetCatalogLoadStatus LoadCatalogFromProject(string projectRootPath)
Loads the asset catalog stored in the project's cache and replaces the current database contents.
Parameters:
projectRootPath(string): The absolute project root path.
Returns: AssetCatalogLoadStatus
- Whether the catalog was read, was absent, or was present but unusable. Callers that open a project for a user should act on
Unreadablerather than carry on with an empty database, which presents as every scene opening empty.
LoadRuntimeCatalog
public void LoadRuntimeCatalog(string runtimeRootPath)
Loads the runtime catalog from an exported game output and replaces the current database contents.
Parameters:
runtimeRootPath(string): The absolute exported runtime root path.
SaveDatabase
public void SaveDatabase(string path)
Saves the current database records as a simple dictionary JSON file.
Parameters:
path(string): The target file path.
LoadDatabase
public void LoadDatabase(string path)
Loads the database from a simple dictionary JSON file.
Parameters:
path(string): The source file path.
SaveCatalog
public void SaveCatalog(string projectRootPath)
Saves the current asset catalog into the project's cache.
Parameters:
projectRootPath(string): The absolute project root path.
RegisterAsset
public bool RegisterAsset(Asset? asset, string? importedPrimaryContentPath = null)
Registers or updates an asset entry using the provided metadata.
Parameters:
asset(Asset?): The asset metadata.importedPrimaryContentPath(string?): Optional absolute imported payload path. (Default:null)
Returns: bool
trueif the asset was registered; otherwise,false.
RegisterChildAsset
public bool RegisterChildAsset(Guid parentAssetId, Asset? child, string? importedContentPath = null)
Registers or updates a child asset — a material or texture declared inside a model file rather than by a source file of its own. The child has no .meta; it is addressed through its parent, and its payload lives in the parent's import directory.
Parameters:
parentAssetId(Guid): Identifier of the asset the child was imported from.child(Asset?): The child asset metadata.importedContentPath(string?): Absolute path of the child's serialized payload. (Default:null)
Returns: bool
truewhen the child was registered; otherwisefalse.
RemoveChildAssets
public int RemoveChildAssets(Guid parentAssetId, IReadOnlySet<Guid>? keep = null)
Removes every child asset of parentAssetId except those in keep. Called after a reimport so slots that no longer exist in the source file — a material the artist deleted — do not linger in the catalog.
Parameters:
parentAssetId(Guid): Identifier of the parent asset.keep(IReadOnlySet? ): Child identifiers that are still valid. Pass an empty set to remove all. (Default:null)
Returns: int
- The number of child records removed.
GetChildAssets
public IReadOnlyCollection<AssetRecord> GetChildAssets(Guid parentAssetId)
Gets the child assets registered against parentAssetId.
Parameters:
parentAssetId(Guid): Identifier of the parent asset.
Returns: IReadOnlyCollection<AssetRecord>
- A snapshot of the parent's child records.