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); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.