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); }
protected virtual void OnSceneGUI(SceneView _sceneView) { if (Playable == null) { return; } #if UNITY_2018_1_OR_NEWER TimelineLiteAsset inspectedAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset; #else TimelineLiteAsset inspectedAsset = UnityEditor.Timeline.TimelineEditor.timelineAsset as TimelineLiteAsset; #endif if (inspectedAsset == null) { return; } // 始终调用 foreach (var trackAsset in inspectedAsset.GetOutputTracks()) { TLBasicTrackAsset basicTrackAsset = trackAsset as TLBasicTrackAsset; if (basicTrackAsset == null) { continue; } foreach (var timelineClip in basicTrackAsset.GetClips()) { ISceneGUI asset = timelineClip.asset as ISceneGUI; if (asset != null) { asset.SceneGUI(Playable, timelineClip, indicatorFrame); } } } #if UNITY_2019_1_OR_NEWER // 只有选中后调用 foreach (var timelineClip in TimelineEditor.selectedClips) { ISceneGUI asset = timelineClip.asset as ISceneGUI; if (asset != null) { asset.SceneGUISelected(Playable, timelineClip, indicatorFrame); } } #endif }
protected virtual void OnDrawGizmos() { #if UNITY_2018_1_OR_NEWER TimelineLiteAsset inspectedAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset; #else TimelineLiteAsset inspectedAsset = UnityEditor.Timeline.TimelineEditor.timelineAsset as TimelineLiteAsset; #endif if (inspectedAsset == null) { return; } // 始终调用 foreach (var trackAsset in inspectedAsset.GetOutputTracks()) { TLBasicTrackAsset basicTrackAsset = trackAsset as TLBasicTrackAsset; if (basicTrackAsset == null) { continue; } foreach (var timelineClip in trackAsset.GetClips()) { IDrawGizmos asset = timelineClip.asset as IDrawGizmos; if (asset != null) { asset.DrawGizmos_Lite(Playable, timelineClip, IndicatorFrame); } } } foreach (var timelineClip in TimelineEditor.selectedClips) { IDrawGizmos asset = timelineClip.asset as IDrawGizmos; if (asset != null) { asset.DrawGizmosSelected_Lite(Playable, timelineClip, IndicatorFrame); } } }