版本: Unity 6 (6000.0)
语言英语
  • C#

AssetDatabase.SetImporterOverride

建议更改

成功!

感谢您帮助我们改进 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们会阅读用户提出的每项更改建议,并在适用的情况下进行更新。

关闭

提交失败

由于某种原因,您的更改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们改进 Unity 文档的质量。

关闭

取消

声明

public static void SetImporterOverride(string path);

参数

path 资产路径。

描述

为资产设置要使用的特定导入器。

可以使用覆盖扩展列表或复合扩展将多个导入器注册到单个资产。

using UnityEngine;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine.Assertions;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Example Importer Actions")] static void AllImporterActions() { //This sets CubeImporter to be used for the asset AssetDatabase.SetImporterOverride<CubeImporterOverride>("Assets/CompanionCube.cube"); Debug.Log("New importer: " + AssetDatabase.GetImporterOverride("Assets/CompanionCube.cube"));

//This clears importer override and sets it to null AssetDatabase.ClearImporterOverride("Assets/CompanionCube.cube"); // This asset does not have an Importer Override anymore. The Default Importer is used ( CubeImporter ). Assert.IsNull(AssetDatabase.GetImporterOverride("Assets/CompanionCube.cube")); } }

//This importer is the Default Importer for the .cube extension. [ScriptedImporter(1, "cube")] public class CubeImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var position = new Vector3(0, 0, 0); cube.transform.position = position; } }

//This importer is the Default Importer for the .composite.cube extension. [ScriptedImporter(1, "composite.cube")] public class CompositeCubeImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var position = new Vector3(1, 1, 1); cube.transform.position = position; } }

//This importer is an Override Importer for the .cube extension. [ScriptedImporter(1, null,new []{ "cube" })] public class CubeImporterOverride : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); // 'cube' is a GameObject and will be automatically converted into a prefab ctx.AddObjectToAsset("main obj", cube); ctx.SetMainObject(cube); } }