zoukankan      html  css  js  c++  java
  • 官方 Animator 例子解析 Animator.MatchTarget

    一、官方的解释

     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 Description
    12 
    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     /// <summary>
     9     /// 匹配 目标
    10     /// </summary>
    11     public Transform RightHand;
    12     bool hasJumped = false;
    13 
    14 
    15     // Use this for initialization
    16     void Start () {
    17 
    18         animator = GetComponent<Animator>();
    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 frame
    35     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 }
  • 相关阅读:
    把TXT GB2312文件转换成TXT UTF8文件
    把ANSI格式的TXT文件批量转换成UTF-8文件类型
    GB2312转换成UTF-8与utf_8转换成GB2312
    SQL 字符串处理函数大全
    编写一个程序,建立一个动态数组,为动态数组的元素赋值,显示动态数组的值并删除动态数组--简单
    设计一个使用常量成员函数的示范程序-简单
    声明一个复数类complex,使用友元函数add实现复数的加法-简单
    使用内联函数设计一个类,用来表示直角坐标系中的任意一条直线并输出它的属性
    设计一个点类point,再设计一个矩形类,矩形类使用point类的两个坐标点作为矩形的对角顶点,并可以输出4个坐标值和面积。使用测试程序验证程序。
    利用函数模板设计一人求数组元素总和的函数,并检验之-简单
  • 原文地址:https://www.cnblogs.com/chongxin/p/4104441.html
Copyright © 2011-2022 走看看