[Unity基础]Timeline的简单使用
參考鏈接:
https://www.jianshu.com/p/56b56d80fbc8
https://www.jianshu.com/p/20801229717a
Timeline需要unity2017以上
1.點擊菜單欄Window/Sequencing/Timeline打開窗口
創建一個空物體,點擊“Create”,這時會創建一個.playable的資源,同時會為該物體掛上“PlayableDirector”和“Animator”組件,其中PlayableDirector是用來播放.playable文件的
2.將1個模型預制體拖到上面的Timeline根物體下,然后將模型預制體中帶有“Animator”組件的子物體拖到Track區域上,然后選擇Animation軌道
3.將該模型的動畫拖上去,運行游戲,這時Timeline的動畫會覆蓋模型動畫控制器的動畫,即播放的是Timeline的動畫
4.自定義擴展
PlayableBehaviour
1 using UnityEngine;
2 using UnityEngine.Playables;
3
4 public class LightPlayableBehaviour : PlayableBehaviour
5 {
6 public Light light = null;
7 public Color color = Color.white;
8 public float intensity = 1f;
9
10 public override void OnGraphStart(Playable playable)
11 {
12 base.OnGraphStart(playable);
13 Debug.Log("OnGraphStart");
14 }
15
16 public override void OnGraphStop(Playable playable)
17 {
18 base.OnGraphStop(playable);
19 Debug.Log("OnGraphStop");
20 }
21
22 public override void OnBehaviourPlay(Playable playable, FrameData info)
23 {
24 base.OnBehaviourPlay(playable, info);
25 Debug.Log("OnBehaviourPlay");
26 light.color = color;
27 light.intensity = intensity;
28 }
29
30 public override void OnBehaviourPause(Playable playable, FrameData info)
31 {
32 base.OnBehaviourPause(playable, info);
33 Debug.Log("OnBehaviourPause");
34 light.color = Color.white;
35 light.intensity = 1;
36 }
37
38 public override void ProcessFrame(Playable playable, FrameData info, object playerData)
39 {
40 base.ProcessFrame(playable, info, playerData);
41 Debug.Log("ProcessFrame");
42 }
43 }
PlayableAsset
1 using UnityEngine;
2 using UnityEngine.Playables;
3
4 public class LightPlayableAsset : PlayableAsset
5 {
6 public ExposedReference<Light> light;
7 public Color color = Color.white;
8 public float intensity = 1.0f;
9
10 public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
11 {
12 var scriptPlayable = ScriptPlayable<LightPlayableBehaviour>.Create(graph);
13 var behaviour = scriptPlayable.GetBehaviour();
14 behaviour.light = light.Resolve(graph.GetResolver());
15 behaviour.color = color;
16 behaviour.intensity = intensity;
17 return scriptPlayable;
18 }
19 }
如下,這樣就能創建自定義的PlayableAsset
選中該PlayableAsset,PlayableAsset腳本的作用是將面板的值賦給PlayableBehaviour;而PlayableBehaviour則是對這些值進行操作
執行順序:
OnGraphStart->OnBehaviourPause->OnBehaviourPlay->ProcessFrame->OnBehaviourPause->OnGraphStop
總結
以上是生活随笔為你收集整理的[Unity基础]Timeline的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谷歌浏览器皮肤
- 下一篇: 如何用手机设置水星路由器手机如何进入水星