从导入的模型中删除组件(未实例化游戏对象)



最近我一直在Unity中使用Asset Importer/Model Importer,我成功地使用C#脚本删除了导入的3D模型上的CameraLight组件。但是我的问题是我无法删除似乎几乎每个模型上都有的Animator组件。 我正在使用的代码:

importedModel = (ModelImporter)AssetImporter.GetAtPath("Assets/Resources/" + Path.GetFileName(fileName));
importedModel.importAnimation = false;//This is NOT working (Model still has Animator)
importedModel.importCameras = false; //This is working
importedModel.importLights = false; //This is working
importedModel.meshCompression = ModelImporterMeshCompression.High;
AssetDatabase.WriteImportSettingsIfDirty(importedModel.assetPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

我尝试过的另一件事是从模型中获取实际的Animator组件,然后将其销毁。我使用以下代码成功获取了对该组件的引用:

foreach (Animator animatorComponent in Resources.FindObjectsOfTypeAll<Animator>())        
DestroyImmediate(animatorComponent, true);

但是,当我使用该DestroyImmediate组件仍然存在时。
如何从我的 3D 模型中删除/停用Animator组件?

根据 ModelImporter,您可以使用 animationType 属性指定Animator generation mode

选项包括:

  • 没有
  • 遗产
  • 通用

在您的情况下,这将解决问题;

importedModel.animationType = ModelImporterAnimationType.None;

最新更新