unity旧动画系统之animationState

多数情况下,Animation已经满足使用。如果你需要完全控制动画混合,可以使用AnimationState。播放动画时,AnimationState允许你修改速度,权值,时间和层;
照旧贴上测试代码:

if (Input.GetKeyDown(KeyCode.A))
        {
            //动画播放速度,1为正常速度,控制速度快慢
           // _animation["attack01"].speed = 0.2f; 
            _animation["attack01"].speed = -0.2f; //负数表示动画倒过来播放
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //禁止动画 在动画再次启用之前,动画时间将被暂停
            _animation["attack01"].enabled = false;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            //启用动画
            _animation["attack01"].enabled = true;
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //动画剪辑的长度  以秒为单位
            print(_animation["attack01"].length);
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //动画剪辑的名字
            print(_animation["attack01"].name);
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //当前动画剪辑的时间,如果时间大于动画剪辑长度那么wrapMode设置效果就出来了,取值范围0-正无穷
            print(_animation["attack01"].time);
        }
 if (Input.GetKeyDown(KeyCode.A))
        {
            //动画的归一化时间,取0-10表示动画开头,1是结尾
            _animation["attack01"].normalizedTime = 0f;
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //动画的wrap模式 和animation中的wrapMode一样
            _animation["attack01"].wrapMode = WrapMode.PingPong;
        }
if (Input.GetKeyDown(KeyCode.A))
        {
            //默认初始化情况下Animation组件中的全部AnimationState的layer=0,weight=0, enable=false
            //当勾选了animation组件上的playautomatically时,layer=0,weight=1,enable=true;
            //同一层动画的混合播放
            //结果就是攻击和行走两个动画体现1:1的混合效果
            AnimationState attack = _animation["attack01"];
            AnimationState walk = _animation["walk"];
            //attack.layer = 1;attack.weight = 1;attack.enabled = true;
            //walk.layer = 1;walk.weight = 1;walk.enabled = true;

            //高层动画覆盖低层动画
            //表现结果就是只有攻击没有走路的动画
           // attack.layer = 1;attack.weight = 1;attack.enabled = true;
          //  walk.layer = 0;walk.weight = 1;walk.enabled = true;

            //高层动画和低层动画混合
            //高层权重0.5,低层权重0.5,表现出的结果就是 两个动画1:1的混合效果
            //attack.layer = 1;attack.weight = 0.5f;attack.enabled = true;
           // walk.layer = 0;walk.weight = 0.5f;walk.enabled = true;

            //总结出来的结果:层越高,动画优先级越高;权重表示该骨骼点受动画的影响程度
        }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationTest : MonoBehaviour {
    Animation _animation;
    AnimationState _state;
    public AnimationClip clip01;
    public Transform guge;
    // Use this for initialization
    void Start () {
        _animation = GameObject.Find("aaa").GetComponent<Animation>();
    }
    void Update ()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            //该方法传入一个骨骼节点的transform,产生的效果就是 
            //动画片段animationClip只会影响该节点和其子节点,而对其他骨骼不产生影响
            //这就是unity局部动画的搞法
            _animation["attack01"].AddMixingTransform(guge);
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            //移除已经通过addmixingtransform函数变换的骨骼节点的效果
            _animation["attack01"].RemoveMixingTransform(guge);
        }

    }
}

猜你喜欢

转载自blog.csdn.net/fenglele_fans/article/details/80364615