Version: 2017.3

AssetPostprocessor

class in UnityEditor

切换到手册

描述

AssetPostprocessor 允许您挂接到导入管线并在导入资源前后运行脚本。

在模型导入期间,系统将按以下顺序调用函数:
- OnPreprocessModel 是在最开始时调用的,您可以覆盖在整个模型导入过程中使用的 ModelImporter 设置。
- 导入网格和材质后,我们会从导入的节点创建游戏对象层级。代表导入的节点的每个游戏对象均会获取相应的 MeshFilter、MeshRenderer 和 MeshCollider 组件。向 MeshRenderer 分配材质之前,系统会调用 OnAssignMaterialModel 函数。
- 在游戏对象初始化 MeshRenderer 之后且存在“userdata”时,系统会调用 OnPostprocessGameObjectWithUserProperties。这发生在生成子游戏对象之前。
- 如果在先前的阶段中未禁用动画生成(请参阅 ModelImporter.generateAnimations),则会生成带蒙皮的网格和动画。如果可能,系统还会创建化身并优化游戏对象层级。之后,系统将为根游戏对象调用 OnPostprocessModel

系统会在 SpeedTree 资源(.spm 文件)上调用 OnPreprocessSpeedTreeOnPostprocessSpeedTree,与调用 OnPreprocessModelOnPostprocessModel 的方式相同,区别在于 SpeedTreeImporter 类型是 assetImporter

在制作流程中,AssetPostprocessor 应始终放置在项目中预先构建的 dll 中,而非脚本中。 AssetPostprocessor 会更改导入的资源的输出,因此,如果其中一个脚本出现编译错误,就会导致资源以不同的方式导入。 在制作流程中操作时,这是一个严重的问题。通过对 AssetPostprocessor 使用 dll,您可以确保在脚本出现编译错误时,也能够始终执行 AssetPostprocessor。 通过此方法,您可以覆盖导入设置中的默认值,也可以修改纹理或网格之类的导入数据。

变量

assetImporter对资源导入器的引用。
assetPath要导入的资源的路径名称。

公共函数

GetPostprocessOrder覆盖导入器的处理顺序。
GetVersion返回资源后处理器的版本。
LogError将导入错误消息记录到控制台。
LogWarning将导入警告记录到控制台。

消息

OnAssignMaterialModel提供源材质。
OnPostprocessAllAssets在完成任意数量的资源导入后(当资源进度条到达末尾时)调用此函数。
OnPostprocessAssetbundleNameChanged将资源分配给其他资源捆绑包时调用的处理程序。
OnPostprocessAudioAdd this function in a subclass to get a notification when an audio clip has completed importing.
OnPostprocessGameObjectWithUserProperties为每个在导入文件中至少附加了一个用户属性的游戏对象调用此函数。
OnPostprocessMaterialAdd this function in a subclass to get a notification when a Material asset has completed importing.
OnPostprocessModelAdd this function in a subclass to get a notification when a model has completed importing.
OnPostprocessSpeedTreeAdd this function in a subclass to get a notification when a SpeedTree asset has completed importing.
OnPostprocessSpritesAdd this function in a subclass to get a notification when an texture of sprite(s) has completed importing.
OnPostprocessTextureAdd this function in a subclass to get a notification when a texture has completed importing just before.
OnPreprocessAnimationAdd this function in a subclass to get a notification just before animation from a model (.fbx, .mb file etc.) is imported.
OnPreprocessAudioAdd this function in a subclass to get a notification just before an audio clip is being imported.
OnPreprocessModelAdd this function in a subclass to get a notification just before a model (.fbx, .mb file etc.) is imported.
OnPreprocessSpeedTreeAdd this function in a subclass to get a notification just before a SpeedTree asset (.spm file) is imported.
OnPreprocessTextureAdd this function in a subclass to get a notification just before the texture importer is run.