如何用代码设置unity2018.4版本中模型导入为Generic模式时的AvatarDefinition参数为copyfromotheravatar
时间: 2024-02-24 12:58:55 浏览: 22
在Unity中,可以使用`ModelImporter`类来设置模型导入时的AvatarDefinition参数。要将AvatarDefinition参数设置为copyfromotheravatar,并将模型导入为Generic模式,可以按照以下步骤进行:
1. 获取模型导入器:
```csharp
ModelImporter importer = AssetImporter.GetAtPath("模型路径") as ModelImporter;
```
2. 设置导入模式为Generic:
```csharp
importer.animationType = ModelImporterAnimationType.Generic;
```
3. 设置AvatarDefinition参数为copyfromotheravatar:
```csharp
importer.humanDescription = new HumanDescription();
importer.humanDescription.custom = true;
importer.CopyAvatarAndSetAsDefault();
```
在这个设置下,Unity将会尝试复制模型中任何已存在的AvatarDefinition,或者使用项目中的默认AvatarDefinition,以便在导入时为该模型创建一个Avatar。注意,在Generic模式下,AvatarDefinition中的一些参数将被忽略,包括`armStretch`、`legStretch`、`feetSpacing`和`hasTranslationDoF`。因此,上述代码中没有设置这些参数的值。
最后,别忘了保存并重新导入模型:
```csharp
importer.SaveAndReimport();
```