Skip to main content

Editor.Model.AssetManager

Class

Manages project assets — creating, importing, finding, and organizing assets within the project.

Index

Example

const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const assetManager = model.project.assetManager;

console.log(`Total assets: ${assetManager.assets.length}`);
console.log(`Assets directory: ${assetManager.assetsDirectory}`);
console.log(`Cache directory: ${assetManager.cacheDirectory}`);

for (const asset of assetManager.assets.slice(0, 5)) {
console.log(` Asset: ${asset.name} (${asset.getTypeName()})`);
}

Extends

Properties

assets

readonly assets: Asset[]

Array of all assets currently loaded in the project.


assetsDirectory

readonly assetsDirectory: Path

Absolute path to the project's assets directory.


cacheDirectory

readonly cacheDirectory: Path

Absolute path to the project's asset cache directory.

Methods

createNativeAsset()

createNativeAsset(assetType, baseName, relativeDestinationDir): Asset

Creates a new native asset of the specified type at the given destination path and returns it.

Parameters

ParameterType
assetTypestring
baseNamestring
relativeDestinationDirSourcePath

Returns

Asset


createPackage()

createPackage(requestedAssets, relativeDestinationDir, packageName, packageOption): AssetImportMetadata

Packages a set of assets into a single package file at the specified destination and returns the resulting import metadata.

Parameters

ParameterType
requestedAssetsAssetImportMetadata[]
relativeDestinationDirSourcePath
packageNamestring
packageOptionPackageOption

Returns

AssetImportMetadata


duplicate()

duplicate(fileMeta, relativeDestinationDir?): AssetImportMetadata

Duplicates a source file that holds a single asset into the given directory, or beside the original when omitted, under a unique name and returns the copy's import metadata. Packages, package items, and files with dependent files cannot be duplicated.

Parameters

ParameterType
fileMetaAssetImportMetadata
relativeDestinationDir?SourcePath

Returns

AssetImportMetadata


exportAssets()

exportAssets(requestedAssets, absoluteDestination): AssetImportMetadata[]

Exports the specified assets to an absolute destination path and returns metadata for the exported assets.

Parameters

ParameterType
requestedAssetsAssetImportMetadata[]
absoluteDestinationPath

Returns

AssetImportMetadata[]


exportSceneObjects()

exportSceneObjects(topLevelSceneObjects, absoluteDestination): AssetImportMetadata[]

Exports top-level scene objects as assets to an absolute destination path and returns the resulting import metadata.

Parameters

ParameterType
topLevelSceneObjectsSceneObject[]
absoluteDestinationPath

Returns

AssetImportMetadata[]


findCopyOrImport()

findCopyOrImport(absoluteSourcePath, relativeDestinationDir?, options?): AssetImportMetadata

Finds an existing imported copy of a file by its absolute source path, optionally scoped to a destination directory.

Parameters

ParameterType
absoluteSourcePathPath
relativeDestinationDir?SourcePath
options?any

Returns

AssetImportMetadata


findImportedCopy()

findImportedCopy(absoluteSourcePath, relativeDestinationDir?, options?): AssetImportMetadata

Find a copy, if it exists, of a file.

Parameters

ParameterType
absoluteSourcePathPath
relativeDestinationDir?SourcePath
options?any

Returns

AssetImportMetadata


getFileMeta()

getFileMeta(relativeFilePath): AssetImportMetadata

Returns import metadata for the asset at the given relative file path.

Parameters

ParameterType
relativeFilePathSourcePath

Returns

AssetImportMetadata


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


importExternalFile()

importExternalFile(absoluteSourcePath, relativeDestinationDir?, resultType?, importSettings?): ImportResult

Imports an external file into the project synchronously and returns its import metadata.

Parameters

ParameterType
absoluteSourcePathPath
relativeDestinationDir?SourcePath
resultType?ResultType
importSettings?ImportSettings

Returns

ImportResult


importExternalFileAsync()

importExternalFileAsync(absoluteSourcePath, relativeDestinationDir?, resultType?, importSettings?): Promise<ImportResult>

Imports an external file into the project asynchronously and returns a promise resolving to its import metadata.

Parameters

ParameterType
absoluteSourcePathPath
relativeDestinationDir?SourcePath
resultType?ResultType
importSettings?ImportSettings

Returns

Promise<ImportResult>


instantiate()

instantiate(assets, params?): Promise<Prefabable[]>

Instantiates an asset into the scene and returns the resulting scene object.

Parameters

ParameterType
assetsAsset[]
params?InstantiationParams

Returns

Promise<Prefabable[]>


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


move()

move(fileMeta, relativeDestinationDir): void

Moves an asset to a new destination path within the project.

Parameters

ParameterType
fileMetaAssetImportMetadata
relativeDestinationDirSourcePath

Returns

void


remove()

remove(relativeFilePath): void

Removes an asset from the project.

Parameters

ParameterType
relativeFilePathSourcePath

Returns

void


rename()

rename(fileMeta, newName): void

Renames an asset to the specified name.

Parameters

ParameterType
fileMetaAssetImportMetadata
newNamestring

Returns

void


saveAsPrefab()

saveAsPrefab(sceneObject, relativeDestinationDir, preferredName?): ObjectPrefab

Saves a scene object as a new prefab asset at the specified destination.

Parameters

ParameterType
sceneObjectSceneObject
relativeDestinationDirSourcePath
preferredName?string

Returns

ObjectPrefab


saveAsPrefabVariant()

saveAsPrefabVariant(sceneObject, relativeDestinationDir, preferredName?): ObjectPrefab

Saves a scene object as a variant of an existing prefab asset.

Parameters

ParameterType
sceneObjectSceneObject
relativeDestinationDirSourcePath
preferredName?string

Returns

ObjectPrefab


unpack()

unpack(nativePackageRoot): Promise<ImportResult>

Unpacks a packaged asset, extracting its contents into the project.

Parameters

ParameterType
nativePackageRootAssetImportMetadata

Returns

Promise<ImportResult>