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); } }