private static TLTrackData GetTrack(TrackAsset trackAsset) { Type trackAssetType = trackAsset.GetType(); if (trackAssetType == typeof(GroupTrack)) { GroupTrack groupTrack = trackAsset as GroupTrack; TLGroupTrackData group = new TLGroupTrackData(); group.enabled = !trackAsset.muted; group.name = trackAsset.name; foreach (TrackAsset childTrack in groupTrack.GetChildTracks()) { TLTrackData track = GetTrack(childTrack); if (track != null) { group.ChildTracks.Add(track); } } if (group.ChildTracks.Count == 0) { return(null); } return(group); } else if (typeof(TLBasicTrackAsset).IsAssignableFrom(trackAssetType)) { TLBasicTrackAsset basicTrackAsset = trackAsset as TLBasicTrackAsset; // 创建Track对象 TLBasicTrackData basicTrackData = basicTrackAsset.CreateTrackData(); basicTrackData.enabled = !basicTrackAsset.muted; basicTrackData.name = basicTrackAsset.name; // 遍历Track的所有片段 foreach (TimelineClip clip in basicTrackAsset.GetClips()) { TLBasicClipAsset clipAsset = clip.asset as TLBasicClipAsset; TLActionData actionData = clipAsset.CreateActionData(); ActionBaseInfo actionBaseInfo = new ActionBaseInfo(); actionBaseInfo.name = clip.displayName; //actionBaseInfo.triggerOnSkip = clipAsset.TriggerOnSkip; actionBaseInfo.start = (int)clip.GetStartFrame(); actionBaseInfo.end = (int)clip.GetEndFrame(); actionBaseInfo.frameCount = (int)clip.GetFrameCount(); actionBaseInfo.startTime = (float)clip.start; actionBaseInfo.endTime = (float)clip.end; actionBaseInfo.duration = actionBaseInfo.endTime - actionBaseInfo.startTime; actionData.ActionBaseInfo = actionBaseInfo; // 获取类型片段,并添加到Track对象 basicTrackData.Clips.Add(actionData); } return(basicTrackData); } return(null); }
static ITLTrack GetTrack(ITimelineLiteObject _timelineLiteObject, TLTrackData _trackData) { Type trackDataType = _trackData.GetType(); if (trackDataType == typeof(TLGroupTrackData)) { TLGroupTrackData groupTrackData = _trackData as TLGroupTrackData; TLGroupTrack groupTrack = new TLGroupTrack(_timelineLiteObject, _trackData as TLGroupTrackData); foreach (TLTrackData childTrack in groupTrackData.ChildTracks) { ITLTrack track = GetTrack(_timelineLiteObject, childTrack); if (track != null) { groupTrack.ChildTracks.Add(track); } } return(groupTrack); } else /* if (typeof(TLBasicTrackData).IsAssignableFrom(trackDataType))*/ { TLBasicTrackData basicTrackData = _trackData as TLBasicTrackData; TLBasicTrack basicTrack = new TLBasicTrack(_timelineLiteObject, basicTrackData); foreach (TLActionData actionData in basicTrackData.Clips) { Type actionType; if (ActionDataDict.TryGetValue(actionData.GetType(), out actionType)) { ITLAction action = Activator.CreateInstance(actionType, basicTrack, actionData) as ITLAction; if (action != null) { basicTrack.Clips.Add(action); } } } return(basicTrack); } }
// 若有需求可返回自定义的轨道数据对象 public override TLBasicTrackData CreateTrackData() { TLBasicTrackData trackData = new TLBasicTrackData(); return(trackData); }