I am writing a .gltf model importer, and I’m stuck on importing Avatars for use with Avatar Masks. I found BuildGenericAvatar but it only returns empty avatars which don’t work with Avatar Masks. Can anyone give me a working example of importing an avatar?
The following code can be used to test generation in editor:
using UnityEditor;
using UnityEngine;
public class AvatarCreator {
[MenuItem("AvatarTools/CreateAvatar")]
private static void CreateAvatar() {
GameObject activeGameObject = Selection.activeGameObject;
if (activeGameObject != null) {
Avatar avatar = AvatarBuilder.BuildGenericAvatar(activeGameObject, "");
avatar.name = activeGameObject.name;
Debug.Log(avatar.isHuman ? "is human" : "is generic");
var path = string.Format("Assets/{0}.ht", avatar.name.Replace(':', '_'));
AssetDatabase.CreateAsset(avatar, path);
}
}
}