首页 > 其他分享 >Playable API - 简单动画混合2

Playable API - 简单动画混合2

时间:2022-12-18 15:33:36浏览次数:38  
标签:动画 graph Create float API animMixerPlayable dirWeight Playable public

角色在跑步时,同时播放向左或向右倾斜动画

using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

public class SimpleAnimClipMix2 : MonoBehaviour
{
    public AnimationClip runLeftAnimClip;
    public AnimationClip runRightAnimClip;
    public AnimationClip runFrontAnimClip;
    [Range(-1, 1)]
    public float dirWeight;

    private PlayableGraph _graph;
    private AnimationMixerPlayable _animMixerPlayable;

    void Start()
    {
        _graph = PlayableGraph.Create("ChanPlayableGraph");
        var animationOutputPlayable = AnimationPlayableOutput.Create(_graph, "AnimationOutput", GetComponent<Animator>()); //往graph添加output

        _animMixerPlayable = AnimationMixerPlayable.Create(_graph, 3); //往graph添加playable(mixer)
        animationOutputPlayable.SetSourcePlayable(_animMixerPlayable);

        var runLeftAnimClipPlayable = AnimationClipPlayable.Create(_graph, runLeftAnimClip); //往graph添加playable(animClip)
        var runRightAnimClipPlayable = AnimationClipPlayable.Create(_graph, runRightAnimClip); //往graph添加playable(animClip)
        var runFrontAnimClipPlayable = AnimationClipPlayable.Create(_graph, runFrontAnimClip); //往graph添加playable(animClip)

        _graph.Connect(runLeftAnimClipPlayable, 0, _animMixerPlayable, 0);
        _graph.Connect(runRightAnimClipPlayable, 0, _animMixerPlayable, 1);
        _graph.Connect(runFrontAnimClipPlayable, 0, _animMixerPlayable, 2);

        _graph.Play();
    }

    void Update()
    {
        float leftWeight = dirWeight < 0 ? -dirWeight : 0;
        float rightWeight = dirWeight > 0 ? dirWeight : 0;
        float forwardWeight = 1 - leftWeight - rightWeight;

        _animMixerPlayable.SetInputWeight(0, leftWeight);
        _animMixerPlayable.SetInputWeight(1, rightWeight);
        _animMixerPlayable.SetInputWeight(2, forwardWeight);
    }

}

脚本:

运行效果:

PlayableGraph的可视化图形:

 

标签:动画,graph,Create,float,API,animMixerPlayable,dirWeight,Playable,public
From: https://www.cnblogs.com/sailJs/p/16988037.html

相关文章

  • Playable API - AnimationClip与AnimatorController放在一起使用
    与这边类似PlayableAPI-简单动画混合-yanghui01-博客园(cnblogs.com),只是跑动画换成了状态机usingUnityEditor.Animations;usingUnityEngine;usingUnityEng......
  • Playable API - 简单的分层动画混合
    为什么要分层?单个层,同时只能播放一个动画。如果角色想要同时2个不同的动画,那就需要2个层;想要3个不同的动画就要3个层,以此类推。1)不用分层的方法:比如,角色跑的时候,还要有......
  • WebApi 路由机制剖析
    从网上看了WEBAPI理解感觉不错分享一下一、MVC和WebApi路由机制比较1、MVC里面的路由在MVC里面,默认路由机制是通过url路径去匹配对应的action方法,比如/Home/GetUser这个......
  • WebApi 接口参数不再困惑:传参详解
    从网上看了WEBAPI理解感觉是不错的分享一下前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料。如今,使用WebApi也有段时间了,今天就记录下API接口传参......
  • 微软出品自动化神器【Playwright+Java】系列(八) 之 使用 Playwright进行API接口测试
    前言我喜欢周末是因为,可以做一些我自己喜欢的事。比如我插上耳机,写点东西就能坐上一天,这也许算是属于我自己的一份静谧吧。想系统学习请参考:Playwright+Java入门使用Pl......
  • Eolink神技之二、API全生命周期管理
    Eolink神技之二、API全生命周期管理目录​​Eolink神技之二、API全生命周期管理​​​​Eolink全API全生命周期管理解决的问题​​​​演示过程​​​​一、创建项目文档​......
  • PPT 动画-树叶摆动
    插入树叶插入矩形,长宽放大1倍树叶和矩形组合......
  • Playable API - 动画混合
    涉及到动画混合常见例子a)根据行走速度慢慢从走变成跑b)角色在跑步时,同时播放向左或向右倾斜动画c)fps游戏中,角色边跑边攻击(需要动画分层+avatarMask)d) 状态机动画......
  • Playable API - 多个Animation Clip间切换播放
    #用到的脚本usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.Animations;usingUnityEngine.Playables;publicclassPlayAnimClipOneByO......
  • Playable API - 简单播放Animation Clip
    用到的资源:GitHub-unity3d-jp/unitychan-crs:Unity-Chan"CandyRockStar"LiveDemo这边直接在他提供的Scene上修改PlayableAPI来播放AnimationClip的脚本:usin......