summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions')
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs76
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs.meta11
2 files changed, 87 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Extension methods for TrackAssets
+ /// </summary>
+ public static class TrackAssetExtensions
+ {
+ /// <summary>
+ /// Gets the GroupTrack this track belongs to.
+ /// </summary>
+ /// <param name="asset">The track asset to find the group of</param>
+ /// <returns>The parent GroupTrack or null if the Track is an override track, or root track.</returns>
+ public static GroupTrack GetGroup(this TrackAsset asset)
+ {
+ if (asset == null)
+ return null;
+
+ return asset.parent as GroupTrack;
+ }
+
+ /// <summary>
+ /// Assigns the track to the specified group track.
+ /// </summary>
+ /// <param name="asset">The track to assign.</param>
+ /// <param name="group">The GroupTrack to assign the track to.</param>
+ /// <remarks>
+ /// Does not support assigning to a group in a different timeline.
+ /// </remarks>
+ 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);
+ }
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs.meta
new file mode 100644
index 0000000..823e94a
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Extensions/TrackExtensions.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d3721d5c6afa8e545995dfaada328476
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: