Version: 2017.2
public void MatchTarget (Vector3 matchPosition, Quaternion matchRotation, AvatarTarget targetBodyPart, MatchTargetWeightMask weightMask, float startNormalizedTime, float targetNormalizedTime= 1);


matchPosition 我们希望身体部位到达的位置。
matchRotation 我们希望身体部位进行的旋转。
targetBodyPart 匹配中涉及的身体部位。
weightMask 包含匹配位置和旋转的权重的结构。
startNormalizedTime 动画剪辑中的开始时间(0 - 剪辑开头,1 - 剪辑末尾)。
targetNormalizedTime 动画剪辑中的结束时间(0 - 剪辑开头,1 - 剪辑末尾),可以设置为大于 1 的值,以在循环一定次数后触发匹配。例如:2.3 表示在第二次循环的 30% 处触发匹配。


Automatically adjust the gameobject position and rotation so that the AvatarTarget reaches the matchPosition when the current state is at the specified progress.

Target matching only works on the base layer (index 0). You can only queue one match target at a time and you must wait for the first one to finish, otherwise your target matching will be discarded. If you call a MatchTarget with a start time lower than the clip's current normalize time and the clip can loop, MatchTarget will adjust the time to match the next clip loop. ex: start time= 0.2 current normalize time = 0.3, start time will be 1.2.

using UnityEngine;

public class TargetMatchingManager : MonoBehaviour { public void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget target, MatchTargetWeightMask weightMask, float normalisedStartTime, float normalisedEndTime) { var animator = GetComponent<Animator>();

if (animator.isMatchingTarget) return;

float normalizeTime = Mathf.Repeat(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 1f);

if (normalizeTime > normalisedEndTime) return;

animator.MatchTarget(matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); } }