ScriptedImporter

class in UnityEditor.AssetImporters

/

Inherits from:AssetImporter

Switch to Manual

Description

Abstract base class for custom Asset importers.

Scripted 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.

using UnityEngine;
using UnityEditor.AssetImporters;
using System.IO;

[ScriptedImporter(1, "cube")] public class CubeImporter : ScriptedImporter { public float m_Scale = 1;

public override void OnImportAsset(AssetImportContext ctx) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var position = JsonUtility.FromJson<Vector3>(File.ReadAllText(ctx.assetPath));

cube.transform.position = position; cube.transform.localScale = new Vector3(m_Scale, m_Scale, m_Scale);

// 'cube' is a a GameObject and will be automatically converted into a Prefab // (Only the 'Main Asset' is elligible to become a Prefab.) ctx.AddObjectToAsset("main obj", cube); ctx.SetMainObject(cube);

var material = new Material(Shader.Find("Standard")); material.color = Color.red;

// Assets must be assigned a unique identifier string consistent across imports ctx.AddObjectToAsset("my Material", material);

// Assets that are not passed into the context as import outputs must be destroyed var tempMesh = new Mesh(); DestroyImmediate(tempMesh); } }

Public Functions

OnImportAssetThis method must by overriden by the derived class and is called by the Asset pipeline to import files.
SupportsRemappedAssetTypeOverride this method if your ScriptedImporter supports remapping specific asset types.

Messages

GatherDependenciesFromSourceFileA static callback that you can implement to set up artifact dependencies to other Assets, and optimize the order your assets are imported.
OnValidateThis function is called when the importer is loaded or a value is changed in the Inspector.
ResetReset to default values.

Inherited members

Variables

assetBundleNameGet or set the AssetBundle name.
assetBundleVariantПолучите или установите любые пользовательские данные.
assetPathИмя пути ассета для этого импортера. (Read Only)
importSettingsMissingThe value is true when no meta file is provided with the imported asset.
userDataПолучите или установите любые пользовательские данные.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Functions

AddRemapMap a sub-asset from an imported asset (such as an FBX file) to an external Asset of the same type.
GetExternalObjectMapGets a copy of the external object map used by the AssetImporter.
RemoveRemapRemoves an item from the map of external objects.
SaveAndReimportSave asset importer settings if asset importer is dirty.
SetAssetBundleNameAndVariantПолучите или установите любые пользовательские данные.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the object.

Static Functions

GetAtPathВосстанавливает импортер ассетов для ассета в path.
DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.