Version: 2021.2

Undo.RegisterImporterUndo

切换到手册
public static void RegisterImporterUndo (string path, string name);

参数

path Path of the asset importer to register for Undo.
name 撤销操作的名称。

描述

Copies the state of the importer for the given asset path.

This method is used to Undo a AssetDatabaseExperimental.SetImporterOverride operation.

using UnityEditor;
using UnityEngine;
using UnityEditor.AssetImporters;
using UnityEditor.Experimental;

[ScriptedImporter(1, null, new[] {"fbx"})] class MyFBXImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { var go = new GameObject("root"); ctx.AddObjectToAsset("root", go); ctx.SetMainObject(go); } }

class ChangeImporterOverrideWithUndo { [MenuItem("Assets/Change Importer To MyFBXImporter With Undo")] static void ChangeImporterWithUndo() { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); Undo.RegisterImporterUndo(assetPath, "Changed Importer"); AssetDatabaseExperimental.SetImporterOverride<MyFBXImporter>(assetPath); } }