unity2018.4代码设置模型的rig面板avatar definition为copyformotheravatar
时间: 2023-09-24 13:14:08 浏览: 328
在Unity 2018.4中,可以使用以下代码将模型的Rig面板Avatar Definition设置为Copy From Other Avatar:
```csharp
using UnityEditor;
using UnityEngine;
public class AvatarDefinitionSetter : MonoBehaviour
{
[SerializeField] private Avatar sourceAvatar;
private void OnEnable()
{
if (sourceAvatar != null)
{
var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(gameObject));
var modelImporter = importer as ModelImporter;
if (modelImporter == null) return;
modelImporter.animationType = ModelImporterAnimationType.Human;
modelImporter.avatarSetup = ModelImporterAvatarSetup.CopyFromOther;
modelImporter.sourceAvatar = sourceAvatar;
AssetDatabase.ImportAsset(importer.assetPath);
}
}
}
```
请注意,上述代码需要将源Avatar分配给sourceAvatar变量。在Inspector面板中,将Avatar Definition设置为Copy From Other Avatar,并将Source Avatar设置为sourceAvatar变量所引用的Avatar即可。
另外,请确保模型的Rig面板是可编辑的(即,ModelImporter的Animation Type设置为Humanoid)。如果将Animation Type设置为Generic,则Rig面板的Avatar Definition将不可编辑。
阅读全文
相关推荐
















