Editor.Model.AssetManager
ClassManages project assets — creating, importing, finding, and organizing assets within the project.
Index
Properties
Methods
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
readonlyassets:Asset[]
Array of all assets currently loaded in the project.
assetsDirectory
readonlyassetsDirectory:Path
Absolute path to the project's assets directory.
cacheDirectory
readonlycacheDirectory: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
| Parameter | Type |
|---|---|
assetType | string |
baseName | string |
relativeDestinationDir | SourcePath |
Returns
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
| Parameter | Type |
|---|---|
requestedAssets | AssetImportMetadata[] |
relativeDestinationDir | SourcePath |
packageName | string |
packageOption | PackageOption |
Returns
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
| Parameter | Type |
|---|---|
fileMeta | AssetImportMetadata |
relativeDestinationDir? | SourcePath |
Returns
exportAssets()
exportAssets(
requestedAssets,absoluteDestination):AssetImportMetadata[]
Exports the specified assets to an absolute destination path and returns metadata for the exported assets.
Parameters
| Parameter | Type |
|---|---|
requestedAssets | AssetImportMetadata[] |
absoluteDestination | Path |
Returns
exportSceneObjects()
exportSceneObjects(
topLevelSceneObjects,absoluteDestination):AssetImportMetadata[]
Exports top-level scene objects as assets to an absolute destination path and returns the resulting import metadata.
Parameters
| Parameter | Type |
|---|---|
topLevelSceneObjects | SceneObject[] |
absoluteDestination | Path |
Returns
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
| Parameter | Type |
|---|---|
absoluteSourcePath | Path |
relativeDestinationDir? | SourcePath |
options? | any |
Returns
findImportedCopy()
findImportedCopy(
absoluteSourcePath,relativeDestinationDir?,options?):AssetImportMetadata
Find a copy, if it exists, of a file.
Parameters
| Parameter | Type |
|---|---|
absoluteSourcePath | Path |
relativeDestinationDir? | SourcePath |
options? | any |
Returns
getFileMeta()
getFileMeta(
relativeFilePath):AssetImportMetadata
Returns import metadata for the asset at the given relative file path.
Parameters
| Parameter | Type |
|---|---|
relativeFilePath | SourcePath |
Returns
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
importExternalFile()
importExternalFile(
absoluteSourcePath,relativeDestinationDir?,resultType?,importSettings?):ImportResult
Imports an external file into the project synchronously and returns its import metadata.
Parameters
| Parameter | Type |
|---|---|
absoluteSourcePath | Path |
relativeDestinationDir? | SourcePath |
resultType? | ResultType |
importSettings? | ImportSettings |
Returns
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
| Parameter | Type |
|---|---|
absoluteSourcePath | Path |
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
| Parameter | Type |
|---|---|
assets | Asset[] |
params? | InstantiationParams |
Returns
Promise<Prefabable[]>
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
move()
move(
fileMeta,relativeDestinationDir):void
Moves an asset to a new destination path within the project.
Parameters
| Parameter | Type |
|---|---|
fileMeta | AssetImportMetadata |
relativeDestinationDir | SourcePath |
Returns
void
remove()
remove(
relativeFilePath):void
Removes an asset from the project.
Parameters
| Parameter | Type |
|---|---|
relativeFilePath | SourcePath |
Returns
void
rename()
rename(
fileMeta,newName):void
Renames an asset to the specified name.
Parameters
| Parameter | Type |
|---|---|
fileMeta | AssetImportMetadata |
newName | string |
Returns
void
saveAsPrefab()
saveAsPrefab(
sceneObject,relativeDestinationDir,preferredName?):ObjectPrefab
Saves a scene object as a new prefab asset at the specified destination.
Parameters
| Parameter | Type |
|---|---|
sceneObject | SceneObject |
relativeDestinationDir | SourcePath |
preferredName? | string |
Returns
saveAsPrefabVariant()
saveAsPrefabVariant(
sceneObject,relativeDestinationDir,preferredName?):ObjectPrefab
Saves a scene object as a variant of an existing prefab asset.
Parameters
| Parameter | Type |
|---|---|
sceneObject | SceneObject |
relativeDestinationDir | SourcePath |
preferredName? | string |
Returns
unpack()
unpack(
nativePackageRoot):Promise<ImportResult>
Unpacks a packaged asset, extracting its contents into the project.
Parameters
| Parameter | Type |
|---|---|
nativePackageRoot | AssetImportMetadata |
Returns
Promise<ImportResult>