当前位置:   article > 正文

Unity代码动态创建Timeline

creating a timeline system by unityeditor and gui.

最近需要通过配置表生成Timeline,自己测试通过,代码如下:

 1 using UnityEditor;
 2 using UnityEngine;
 3 using UnityEngine.Timeline;
 4 
 5 
 6 public class Test : EditorWindow
 7 {
 8     string m_PartID;
 9 
10     [MenuItem("Assets/TimelineGenerator")]
11     public static void Init()
12     {
13         GetWindow<Test>().Show();
14     }
15 
16     public void OnGUI()
17     {
18         GUILayout.BeginVertical();
19 
20         GUILayout.BeginHorizontal();
21         GUILayout.Label("PartID");
22         m_PartID = GUILayout.TextField(m_PartID);
23         GUILayout.EndHorizontal();
24 
25         if (GUILayout.Button("Generate"))
26             Generate();
27 
28         GUILayout.EndVertical();
29     }
30 
31     void Generate()
32     {
33         var asset = TimelineAsset.CreateInstance<TimelineAsset>();
34         AssetDatabase.CreateAsset(asset, "Assets/Test/test.playable");
35         var track = asset.CreateTrack<PlayableTrack>(null, "tt");
36         var clip = track.CreateClip<Talk>();
37         clip.displayName = "QAQ";
38         AssetDatabase.SaveAssets();
39     }
40 }

 

转载于:https://www.cnblogs.com/liucUP/p/10691369.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/95474
推荐阅读
相关标签
  

闽ICP备14008679号