最近需要通过配置表生成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 }