Version: 2021.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% 处触发匹配。
completeMatch Allows you to specify what should happen if the MatchTarget function is interrupted. A value of true causes the GameObject to immediately move to the matchPosition if interrupted. A value of false causes the GameObject to stay at its current position if interrupted.

描述

自动调整 GameObject 的位置和旋转。

调整 GameObject 的位置和旋转,以便当前状态处于指定的进度时,AvatarTarget 到达 matchPosition。目标匹配仅适用于基础层(索引 0)。 一次只能排队一个匹配目标,并且必须等待第一个匹配目标完成,否则将丢弃目标匹配。 如果调用 MatchTarget 的开始时间小于剪辑的当前标准化时间并且剪辑可以循环,MatchTarget 将调整时间以匹配下一个剪辑循环。例如:开始时间 = 0.2,当前标准化时间 = 0.3,则开始时间将为 1.2。必须启用 Animator.applyRootMotion MatchTarget 才会有效。

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); } }