A game about forced loneliness, made by TACStudios
at master 76 lines 2.5 kB view raw
1using System; 2using UnityEngine; 3using UnityEngine.Timeline; 4using UnityEngine.Playables; 5 6namespace UnityEngine.Timeline 7{ 8 /// <summary> 9 /// Extension methods for TrackAssets 10 /// </summary> 11 public static class TrackAssetExtensions 12 { 13 /// <summary> 14 /// Gets the GroupTrack this track belongs to. 15 /// </summary> 16 /// <param name="asset">The track asset to find the group of</param> 17 /// <returns>The parent GroupTrack or null if the Track is an override track, or root track.</returns> 18 public static GroupTrack GetGroup(this TrackAsset asset) 19 { 20 if (asset == null) 21 return null; 22 23 return asset.parent as GroupTrack; 24 } 25 26 /// <summary> 27 /// Assigns the track to the specified group track. 28 /// </summary> 29 /// <param name="asset">The track to assign.</param> 30 /// <param name="group">The GroupTrack to assign the track to.</param> 31 /// <remarks> 32 /// Does not support assigning to a group in a different timeline. 33 /// </remarks> 34 public static void SetGroup(this TrackAsset asset, GroupTrack group) 35 { 36 const string undoString = "Reparent"; 37 38 if (asset == null || asset == group || asset.parent == group) 39 return; 40 41 if (group != null && asset.timelineAsset != group.timelineAsset) 42 throw new InvalidOperationException("Cannot assign to a group in a different timeline"); 43 44 45 TimelineUndo.PushUndo(asset, undoString); 46 47 var timeline = asset.timelineAsset; 48 var parentTrack = asset.parent as TrackAsset; 49 var parentTimeline = asset.parent as TimelineAsset; 50 if (parentTrack != null || parentTimeline != null) 51 { 52 TimelineUndo.PushUndo(asset.parent, undoString); 53 if (parentTimeline != null) 54 { 55 parentTimeline.RemoveTrack(asset); 56 } 57 else 58 { 59 parentTrack.RemoveSubTrack(asset); 60 } 61 } 62 63 if (group == null) 64 { 65 TimelineUndo.PushUndo(timeline, undoString); 66 asset.parent = asset.timelineAsset; 67 timeline.AddTrackInternal(asset); 68 } 69 else 70 { 71 TimelineUndo.PushUndo(group, undoString); 72 group.AddChild(asset); 73 } 74 } 75 } 76}