Unity代码动态创建Timeline

最近需要通过配置表生成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().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();
34         AssetDatabase.CreateAsset(asset, "Assets/Test/test.playable");
35         var track = asset.CreateTrack(null, "tt");
36         var clip = track.CreateClip();
37         clip.displayName = "QAQ";
38         AssetDatabase.SaveAssets();
39     }
40 }

 

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

你可能感兴趣的:(Unity代码动态创建Timeline)