PlayableGraph 概述: PlayableGraph是一组API
PlayableGraph常用API:
PlayableGraph
AnimationPlayableOutput: IPlayableOutPut 输出节点
AnimationMixerPlayable: Iplayable 动画混合
AnimationClipPlayable: Iplayable 动画剪辑
可借用第三方可视化工具:
graph-visualizer 插件 进行查看,下载自行百度
废话不多说 ,直接上代码:
1 using UnityEngine;
2 using UnityEngine.Animations;
3 using UnityEngine.Playables;
4
5 public class TestPlayable : MonoBehaviour
6 {
7 private Animator m_Animator;
8
9 [SerializeField]
10 private AnimationClip m_AnimationClip;
11 private PlayableGraph m_PlayableGraph;
12 private AnimationPlayableOutput m_AnimationPlayableOutput;
13
14 void Awake()
15 {
16 m_Animator = GetComponent<Animator>();
17 //创建画布
18 m_PlayableGraph = PlayableGraph.Create("testGraph");
19 //为画布创建一个输出节点
20 m_AnimationPlayableOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "OutPut", m_Animator);
21 Test1();
22 }
23
24 void Test1()
25 {
26 //画布上创建一个动画剪辑,作为输入节点
27 AnimationClipPlayable animationClipPlayable = AnimationClipPlayable.Create(m_PlayableGraph, m_AnimationClip);
28 //连线(设置输出节点的输入源为动画剪辑)
29 m_AnimationPlayableOutput.SetSourcePlayable(animationClipPlayable, 0);
30 //播放
31 m_PlayableGraph.Play();
32 }
33 }