AssetPostprocessor.OnPostprocessModel(GameObject)

Switch to Manual

Description

将此函数添加到一个子类中,以在模型完成导入时获取通知。

借助此函数,您可以修改此函数引用的所导入的游戏对象、网格、动画剪辑。请注意,游戏对象、动画剪辑和网格仅在导入期间存在,导入完成后,系统会立即将其销毁。

This function is called before the final Prefab is created and before it is written to disk, thus you have full control over the generated game objects and components.

Any references to game objects or meshes will become invalid after the import has been completed. Thus it is not possible to create a new Prefab in a different file from OnPostprocessModel that references meshes in the imported fbx file.

root 是导入模型的根游戏对象。

using UnityEngine;
using UnityEditor;

// Adds a mesh collider to each game object that contains collider in its name public class Example : AssetPostprocessor { void OnPostprocessModel(GameObject g) { Apply(g.transform); }

void Apply(Transform t) { if (t.name.ToLower().Contains("collider")) t.gameObject.AddComponent<MeshCollider>();

// Recurse foreach (Transform child in t) Apply(child); } }