博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
官方 Animator 例子解析 Animator.MatchTarget
阅读量:6453 次
发布时间:2019-06-23

本文共 3751 字,大约阅读时间需要 12 分钟。

一、官方的解释

1 Animator.MatchTargetSwitch to Manual 2 void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget targetBodyPart, MatchTargetWeightMask weightMask, float startNormalizedTime, float targetNormalizedTime = 1); 3 Parameters 4  5 matchPosition    The position we want the body part to reach. 6 matchRotation    The rotation in which we want the body part to be. 7 targetBodyPart    The body part that is involved in the match. 8 weightMask    Structure that contains weights for matching position and rotation. 9 startNormalizedTime    Start time within the animation clip (0 - beginning of clip, 1 - end of clip).10 targetNormalizedTime    End time within the animation clip (0 - beginning of clip, 1 - end of clip), values greater than 1 can be set to trigger a match after a certain number of loops. Ex: 2.3 means at 30% of 2nd loop.11 Description12 13 Automatically adjust the gameobject position and rotation so that the AvatarTarget reaches the matchPosition when the current state is at the specified progress.14 15 Target matching only works on the base layer (index 0).

 

二、理解

这个 一般 用于 根运动 动画。 可以用在 人物攀爬 或者 掉落 的动画 时候 进行一些 位置的调整。具体在于理解。上一段官方的例子教程。

1 using UnityEngine; 2 using System.Collections; 3  4 public class TargetMatching : MonoBehaviour 5 { 6  7     private Animator animator; 8     ///  9     /// 匹配 目标10     /// 11     public Transform RightHand;12     bool hasJumped = false;13 14 15     // Use this for initialization16     void Start () {17 18         animator = GetComponent
();19 20 }21 22 void OnGUI()23 {24 GUILayout.Label("Make your character grab any edge!");25 GUILayout.Label("Press Fire1 to trigger Jump animation");26 GUILayout.Label("Added *MatchStart* and *MatchEnd* parameters to the Animator Controller");27 GUILayout.Label("Added *MatchStart* and *MatchEnd* additionnal curves to the Idle_ToJumpUpHigh animation");28 GUILayout.Label("*MatchStart* and *MatchEnd* tell the system when to start cheating the root using MatchTarget API");29 GUILayout.Label("Added a RightHand model child of the MoveThis container, to tell where the right hand should go");30 GUILayout.Label("On the update function, we call MatchTarget");31 GUILayout.Label("Translate the MoveThis object and see how character's hand always reach it"); 32 }33 34 // Update is called once per frame35 void Update () 36 {37 38 if (animator)39 {40 AnimatorStateInfo state = animator.GetCurrentAnimatorStateInfo(0);41 42 if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);43 44 if (state.IsName("Base Layer.JumpUp") || state.IsName("Base Layer.FullJump")) 45 {46 animator.SetBool("Jump", false);47 48 animator.MatchTarget(49 RightHand.position, 50 RightHand.rotation, 51 AvatarTarget.RightHand, 52 new MatchTargetWeightMask(new Vector3(1, 1, 1), 0), 53 /// 动画 曲线 获取54 animator.GetFloat("MatchStart"), 55 animator.GetFloat("MatchEnd"));56 hasJumped = true;57 }58 59 if (hasJumped && state.normalizedTime > 1.2)60 {61 hasJumped = false;62 63 Application.LoadLevel(0);64 }65 66 Debug.Log(" animator.GetFloat MatchStart " + animator.GetFloat("MatchStart") + " state.normalizedTime " + state.normalizedTime);67 }68 69 }70 }

 

转载于:https://www.cnblogs.com/chongxin/p/4104441.html

你可能感兴趣的文章
Discuz!X2.5论坛首页模板请问是哪一个htm文件?
查看>>
Tiny4412裸机程序,时钟操作
查看>>
初始airflow
查看>>
[Android]通过JNI实现卸载自身App后台发送Http请求~
查看>>
java中数组
查看>>
程序猿媛六:ListView的Item点击事件(消息传递)
查看>>
04_项目管理一般知识
查看>>
内存及数据库结构
查看>>
推荐一篇写的最好的事务相关资料的文章
查看>>
设计模式C++实现(5)——原型模式、模板方法模式
查看>>
新东方在线线性代数长线基础班-2-一般阶的行列式
查看>>
获取appstore版本号,本机app版本号,以及跳转appstore整理
查看>>
在win10 docker启动的centos容器中安装nginx
查看>>
Nginx性能优化
查看>>
RabbitMQ与java、Spring结合实例详细讲解
查看>>
让HTTP萌娘帮你记住状态码吧
查看>>
修改virtualenv的python版本
查看>>
5个方法在营销中使用幽默
查看>>
[note]First draft of a report on the EDVAC (1~2)
查看>>
学习Git
查看>>