Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Experimental: this API is experimental and might be changed or removed in the future.

AssetImportContext.SetMainAsset

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public method SetMainAsset(identifier: string, asset: Object): void;
public void SetMainAsset(string identifier, Object asset);
public method SetMainAsset(identifier: string, asset: Object, thumbnail: Texture2D): void;
public void SetMainAsset(string identifier, Object asset, Texture2D thumbnail);

Parameters

identifier A Unique identifier associated to this Asset.
asset The Unity Object that is the sub-Asset.
thumbnail An optional 2D texture to use as the thumbnail for the Asset.

Description

Set's the main Asset to the result of the import operation.

This method can only be called once per import opperation and must be called. Returning without setting a main Asset will result in a failed import opperation

This method allows you to specify which Asset is the main Asset during the import process. Any other Assets which are created during the import will become sub-Assets to this Asset. For example, when importing an FBX file, any Materials and Textures imported from the file become sub-Assets. You must call this method during the OnAssetImport process.

Note: You must make sure that your importer creates a unique identifier for each Asset. You must also make sure that your code regenerates the same identifier each time the file is re-imported, even if sub-Assets have been modified. This allows Unity to keep track of which old sub-Assets have been modified when a file is re-imported, and therefore which should be replaced by the corresponding new versions of the same sub-Assets. The identifier only needs to be unique within the context of the Asset file and not globaly unique across your whole project.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答