Experimental: this API is experimental and might be changed or removed in the future.

ScriptedImporter

class in UnityEditor.Experimental.AssetImporters

/

继承自:AssetImporter

切换到手册

描述

自定义资源导入器的抽象基类。

脚本化导入器是与特定文件扩展名关联的脚本。Unity 的资源管线调用它们来将关联文件的内容转换为资源。

使用 ScriptedImporterAttribute 类可向资源管线注册自定义导入器。

using UnityEngine;
using UnityEditor.Experimental.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); } }

公共函数

OnImportAsset此方法必须由派生类重写,并由资源管线调用来导入文件。

继承的成员

变量

assetBundleName获取或设置 AssetBundle 名称。
assetBundleVariant获取或设置 AssetBundle 变体。
assetPath此导入器的资源的路径名称。(只读)
userData获取或设置任意用户数据。

公共函数

AddRemap将子资源从导入的资源(例如 FBX 文件)映射到同类型的外部资源。
GetExternalObjectMap获取 AssetImporter 使用的外部对象映射的副本。
RemoveRemap从外部对象的映射中删除项。
SaveAndReimport如果资源导入器已标记为“脏”,则保存资源导入器设置。
SetAssetBundleNameAndVariant设置 AssetBundle 名称和变体。

静态函数

GetAtPath在 path 处检索资源的资源导入器。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961