AvatarBuilder.BuildHumanAvatar
Declaration
public static Avatar BuildHumanAvatar(GameObject go, HumanDescription humanDescription);Параметры
| Параметр | Описание |
|---|---|
| Иди | Корневой объект вашей иерархии преобразований. Он должен быть верхним игровым объектом при создании аватара. |
| humanDescription | Гуманитарное описание аватара. |
Возвращаемое значение
Аватар Возвращает Аватар, вы всегда должны всегда проверять, что аватар действителен, прежде чем использовать его с Avatar.isValid.
Описание
Создание аватара.
Аватар создается с помощью поставляемого объекта HumanDescription, который определяет пределы диапазона мышц и параметры перенаправления, такие как поворот руки/ноги и растяжение руки/ноги. Дополнительные ресурсы: HumanDescription.
using System; using System.Collections.Generic; using UnityEngine; // This example automatically builds a humanoid avatar // for the GameObject it is attached to and assigns it // to the Animator. [RequireComponent(typeof(Animator))] public class HumanAvatarBuilderExample : MonoBehaviour { [Serializable] public struct BoneMapping { public BoneMapping(HumanBodyBones bone) { this.bone = bone; transform = null; } public HumanBodyBones bone; public Transform transform; } // Lightweight version of the mapping tool available in // the Avatar Mapping tab. public BoneMapping[] boneMappings = { new BoneMapping(HumanBodyBones.Hips), new BoneMapping(HumanBodyBones.LeftUpperLeg), new BoneMapping(HumanBodyBones.RightUpperLeg), new BoneMapping(HumanBodyBones.LeftLowerLeg), new BoneMapping(HumanBodyBones.RightLowerLeg), new BoneMapping(HumanBodyBones.LeftFoot), new BoneMapping(HumanBodyBones.RightFoot), new BoneMapping(HumanBodyBones.Spine), new BoneMapping(HumanBodyBones.Chest), new BoneMapping(HumanBodyBones.Neck), new BoneMapping(HumanBodyBones.Head), new BoneMapping(HumanBodyBones.LeftShoulder), new BoneMapping(HumanBodyBones.RightShoulder), new BoneMapping(HumanBodyBones.LeftUpperArm), new BoneMapping(HumanBodyBones.RightUpperArm), new BoneMapping(HumanBodyBones.LeftLowerArm), new BoneMapping(HumanBodyBones.RightLowerArm), new BoneMapping(HumanBodyBones.LeftHand), new BoneMapping(HumanBodyBones.RightHand), new BoneMapping(HumanBodyBones.UpperChest) }; HumanBone[] GetHumanBones() { var humanBones = new List<HumanBone>(); string[] boneName = HumanTrait.BoneName; foreach (var kvp in boneMappings) { if (kvp.transform == null) continue; humanBones.Add(new HumanBone { humanName = boneName[(int)kvp.bone], boneName = kvp.transform.name }); } return humanBones.ToArray(); } void Start() { var animator = GetComponent<Animator>(); var avatar = AvatarBuilder.BuildHumanAvatar(gameObject, new HumanDescription { human = GetHumanBones(), skeleton = Array.Empty<SkeletonBone>(), }); avatar.name = "RuntimeAvatar"; animator.avatar = avatar; } }