From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Runtime/Extensions/TrackExtensions.cs | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs') diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs new file mode 100644 index 0000000..87eec1b --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs @@ -0,0 +1,76 @@ +using System; +using UnityEngine; +using UnityEngine.Timeline; +using UnityEngine.Playables; + +namespace UnityEngine.Timeline +{ + /// + /// Extension methods for TrackAssets + /// + public static class TrackAssetExtensions + { + /// + /// Gets the GroupTrack this track belongs to. + /// + /// The track asset to find the group of + /// The parent GroupTrack or null if the Track is an override track, or root track. + public static GroupTrack GetGroup(this TrackAsset asset) + { + if (asset == null) + return null; + + return asset.parent as GroupTrack; + } + + /// + /// Assigns the track to the specified group track. + /// + /// The track to assign. + /// The GroupTrack to assign the track to. + /// + /// Does not support assigning to a group in a different timeline. + /// + public static void SetGroup(this TrackAsset asset, GroupTrack group) + { + const string undoString = "Reparent"; + + if (asset == null || asset == group || asset.parent == group) + return; + + if (group != null && asset.timelineAsset != group.timelineAsset) + throw new InvalidOperationException("Cannot assign to a group in a different timeline"); + + + TimelineUndo.PushUndo(asset, undoString); + + var timeline = asset.timelineAsset; + var parentTrack = asset.parent as TrackAsset; + var parentTimeline = asset.parent as TimelineAsset; + if (parentTrack != null || parentTimeline != null) + { + TimelineUndo.PushUndo(asset.parent, undoString); + if (parentTimeline != null) + { + parentTimeline.RemoveTrack(asset); + } + else + { + parentTrack.RemoveSubTrack(asset); + } + } + + if (group == null) + { + TimelineUndo.PushUndo(timeline, undoString); + asset.parent = asset.timelineAsset; + timeline.AddTrackInternal(asset); + } + else + { + TimelineUndo.PushUndo(group, undoString); + group.AddChild(asset); + } + } + } +} -- cgit v1.2.3