Class ModularImporter
Abstract base class for custom asset importer using an ImporterGraph.
Modular importers are scripts that are associated with specific file extensions. They are invoked by Unity's Asset pipeline to convert the contents of associated files into Assets. Use the ScriptedImporterAttribute class to register custom importers with the Asset pipeline.
Inherited Members
Namespace: UnityEditor.Importer
Assembly: Unity.Importer.Editor.dll
Syntax
public abstract class ModularImporter : ScriptedImporter
Properties
DefaultGraphPath
A project path where the default ImporterGraph to use when the asset is imported for the first time and no graph is set yet.
Declaration
protected virtual string DefaultGraphPath { get; }
Property Value
Type | Description |
---|---|
string |
Examples
using UnityEditor.Importer;
[ModularImporter(version: 1, ext: "sphere")]
public class SphereImporter : ModularImporter
{
protected override ImporterGraph DefaultGraphPath => "Assets/DefaultImporters/SphereImporter.asset";
}
ErrorIdsToTrack
A set of ids to track for analytics.
Declaration
protected virtual HashSet<int> ErrorIdsToTrack { get; }
Property Value
Type | Description |
---|---|
HashSet<int> |
Graph
The ImporterGraph used by the ModularImporter to convert the content of this file into Unity's assets.
Declaration
public LazyLoadReference<ImporterGraph> Graph { get; set; }
Property Value
Type | Description |
---|---|
LazyLoadReference<ImporterGraph> |
ImportSettingOverrides
The import setting overrides declared for this importer.
Declaration
public IReadOnlyList<IGraphValue> ImportSettingOverrides { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IGraphValue> |
WarningIdsToTrack
A set of warning ids to track for analytics.
Declaration
protected virtual HashSet<int> WarningIdsToTrack { get; }
Property Value
Type | Description |
---|---|
HashSet<int> |
Methods
AddImportSettingOverride(IGraphValue)
Add an ImportSetting<T> to the import setting overrides.
Declaration
public ModularImporterValidationResult AddImportSettingOverride(IGraphValue setting)
Parameters
Type | Name | Description |
---|---|---|
IGraphValue | setting | An ImportSetting<T> to add. |
Returns
Type | Description |
---|---|
ModularImporterValidationResult | The ModularImporterValidationResult of this command. |
OnFinishingAssetImport(GraphLogger)
This method is called at the end of the import.
Declaration
protected virtual void OnFinishingAssetImport(GraphLogger graphLogger)
Parameters
Type | Name | Description |
---|---|---|
GraphLogger | graphLogger | The graph logger. |
OnImportAsset(AssetImportContext)
This method is called by the Asset pipeline to import files.
Declaration
public override void OnImportAsset(AssetImportContext ctx)
Parameters
Type | Name | Description |
---|---|---|
AssetImportContext | ctx | This argument contains all the contextual information needed to process the import event and is also used by the custom importer to store the resulting Unity Asset. |
Overrides
Remarks
It is already implemented by the ModularImporter class to validate and execute the Graph. If the import is successful, this method will call ProcessImportResult(IReadOnlyList<IGraphValue>, AssetImportContext) with the result of the graph execution.
ProcessImportResult(IReadOnlyList<IGraphValue>, AssetImportContext)
This method is called at the end of the import if the Graph execution was a success.
Declaration
protected virtual void ProcessImportResult(IReadOnlyList<IGraphValue> results, AssetImportContext ctx)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<IGraphValue> | results | A readonly list of ImportResult<T> that get generated from the Graph execution. |
AssetImportContext | ctx | This argument contains all the contextual information needed to process the import event and is also used by the custom importer to store the resulting Unity Asset. |
Remarks
The default implementation looks for Object to add them in the AssetImportContext as resulting assets of the import. The following ImportResult<T> types are supported:
RemoveImportSettingOverride(IGraphValue)
Remove an ImportSetting<T> from the import setting overrides.
Declaration
public ModularImporterValidationResult RemoveImportSettingOverride(IGraphValue setting)
Parameters
Type | Name | Description |
---|---|---|
IGraphValue | setting | An ImportSetting<T> to remove. |
Returns
Type | Description |
---|---|
ModularImporterValidationResult | The ModularImporterValidationResult of this command. |
Validate()
Validate this ModularImporter.
Declaration
public ModularImporterValidationResult Validate()
Returns
Type | Description |
---|---|
ModularImporterValidationResult | The ModularImporterValidationResult of this validation. |