AssetDatabase

An Interface for accessing assets and performing operations on assets.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

Class Functions
Contains

Is object an asset?

CreateFolder

Create a new folder.

IsMainAsset

Is asset a main asset in the project window?

IsSubAsset

Is asset a sub asset?

GenerateUniqueAssetPath

Creates a new unique path for an asset.

StartAssetEditing

Begin Asset importing. This lets you group several asset imports together into one larger import.

StopAssetEditing

Stop Asset importing. This lets you group several asset imports together into one larger import.

ValidateMoveAsset

Checks if an asset file can be moved from one folder to another. (Without actually moving the file)

MoveAsset

Move an asset file from one folder to another.

RenameAsset

Rename an asset file.

MoveAssetToTrash

Moves the asset at path to the trash.

DeleteAsset

Deletes the asset file at path.

ImportAsset

Import asset at path.

CopyAsset

Duplicates the asset at path and stores it at newPath

WriteImportSettingsIfDirty

Writes the import settings to disk.

CreateAsset

Creates a new asset at path.

AddObjectToAsset

Adds objectToAdd to an existing asset at path.

GetAssetPath

Returns the path name relative to the project folder where the asset is stored

GetAssetOrScenePath

Returns the path name relative to the project folder where the asset is stored

GetTextMetaDataPathFromAssetPath

Gets the path to the text .meta file associasted with an asset

LoadAssetAtPath

Returns the first asset object of type type at given path assetPath.

LoadMainAssetAtPath

Returns the main asset object at assetPath.

LoadAllAssetRepresentationsAtPath

Returns all asset representations at assetPath.

LoadAllAssetsAtPath

Returns an array of all asset objects at assetPath.

Refresh

Import any changed assets.

OpenAsset

Opens the asset with associated application.

AssetPathToGUID

Get the GUID for the asset at path

GUIDToAssetPath

Translate a GUID to its current asset path

SaveAssets

Writes all unsaved asset changes to disk.

GetCachedIcon

Retrieves an icon for the asset at the given asset path.

SetLabels

Replaces that list of labels on an asset.

GetLabels

Returns all labels attached to a given asset.

ClearLabels

Removes all labels attached to an asset.

GetDependencies

Given an asset pathName, returns the list of all assets it depends on.

ExportPackage

Exports the assets identified by assetPathNames to a unitypackage file in fileName.

ImportPackage

Imports package at packagePath into the current project.

IsOpenForEdit

Use IsOpenForEdit to determine if the asset is open for edit by the version control.