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 }