Playable API - AnimationClip与AnimatorController放在一起使用
与这边类似Playable API - 简单动画混合 - yanghui01 - 博客园 (cnblogs.com),只是跑动画换成了状态机
using UnityEditor.Animations; using UnityEngine; using UnityEngine.Animations; using UnityEngine.Playables; public class MixController : MonoBehaviour { public AnimationClip walkAnimClip; public AnimatorController runController; [Range(0, 1)] public float runWeight; 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, 2); //往graph添加playable(mixer) animationOutputPlayable.SetSourcePlayable(_animMixerPlayable); var walkAnimClipPlayable = AnimationClipPlayable.Create(_graph, walkAnimClip); //往graph添加playable(animClip) var runControllerPlayable = AnimatorControllerPlayable.Create(_graph, runController); //往graph添加playable(AnimatorController) _graph.Connect(walkAnimClipPlayable, 0, _animMixerPlayable, 0); _graph.Connect(runControllerPlayable, 0, _animMixerPlayable, 1); _graph.Play(); } void Update() { _animMixerPlayable.SetInputWeight(0, 1 - runWeight); _animMixerPlayable.SetInputWeight(1, runWeight); } }
新建一个状态机:

脚本

运行效果:

PlayableGraph的可视化图形:

参考:
【Unity】简单使用Playable API控制动画 - 知乎 (zhihu.com)

浙公网安备 33010602011771号