static void MoveToTrack_Impl(TimelineClip clip, TrackAsset destinationTrack, Object asset, TrackAsset parentTrack)
        {
            TimelineUndo.PushUndo(asset, k_UndoSetParentTrackText);
            if (parentTrack != null)
            {
                TimelineUndo.PushUndo(parentTrack, k_UndoSetParentTrackText);
            }

            TimelineUndo.PushUndo(destinationTrack, k_UndoSetParentTrackText);

            clip.SetParentTrack_Internal(destinationTrack);

            if (parentTrack == null)
            {
                TimelineCreateUtilities.SaveAssetIntoObject(asset, destinationTrack);
            }
            else if (parentTrack.timelineAsset != destinationTrack.timelineAsset)
            {
                TimelineCreateUtilities.RemoveAssetFromObject(asset, parentTrack);
                TimelineCreateUtilities.SaveAssetIntoObject(asset, destinationTrack);
            }
        }
Exemplo n.º 2
0
        public IMarker CreateMarker(Type type, double time, TrackAsset owner)
        {
            if (!typeof(ScriptableObject).IsAssignableFrom(type) || !typeof(IMarker).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(
                          "The requested type needs to inherit from ScriptableObject and implement IMarker");
            }

            var markerSO = ScriptableObject.CreateInstance(type);
            var marker   = (IMarker)markerSO;

            marker.time = time;

            TimelineCreateUtilities.SaveAssetIntoObject(markerSO, owner);
            TimelineUndo.RegisterCreatedObjectUndo(markerSO, "Create " + type.Name);
            TimelineUndo.PushUndo(owner, "Create " + type.Name);

            Add(markerSO);
            marker.Initialize(owner);

            return(marker);
        }
        /// <summary>
        /// Delete a clip from this timeline.
        /// </summary>
        /// <param name="clip">The clip to delete.</param>
        /// <returns>Returns true if the removal was successful</returns>
        /// <remarks>
        /// This method will delete a clip and any assets owned by the clip.
        /// </remarks>
        public bool DeleteClip(TimelineClip clip)
        {
            if (clip == null || clip.GetParentTrack() == null)
            {
                return(false);
            }
            if (this != clip.GetParentTrack().timelineAsset)
            {
                Debug.LogError("Cannot delete a clip from this timeline");
                return(false);
            }

            TimelineUndo.PushUndo(clip.GetParentTrack(), "Delete Clip");
            if (clip.curves != null)
            {
                TimelineUndo.PushDestroyUndo(this, clip.GetParentTrack(), clip.curves);
            }

            // handle wrapped assets
            if (clip.asset != null)
            {
                DeleteRecordedAnimation(clip);

                // TODO -- we should flag assets and owned, instead of this check...
#if UNITY_EDITOR
                string path = UnityEditor.AssetDatabase.GetAssetPath(clip.asset);
                if (path == UnityEditor.AssetDatabase.GetAssetPath(this))
#endif
                {
                    TimelineUndo.PushDestroyUndo(this, clip.GetParentTrack(), clip.asset);
                }
            }

            var clipParentTrack = clip.GetParentTrack();
            clipParentTrack.RemoveClip(clip);
            clipParentTrack.CalculateExtrapolationTimes();

            return(true);
        }
        /// <summary>
        /// Deletes a track from a timeline, including all clips and subtracks.
        /// </summary>
        /// <param name="track">The track to delete. It must be owned by this Timeline.</param>
        /// <returns>True if the track was deleted successfully.</returns>
        public bool DeleteTrack(TrackAsset track)
        {
            if (track.timelineAsset != this)
            {
                return(false);
            }

            // push before we modify properties
            TimelineUndo.PushUndo(track, "Delete Track");
            TimelineUndo.PushUndo(this, "Delete Track");

            TrackAsset parent = track.parent as TrackAsset;

            if (parent != null)
            {
                TimelineUndo.PushUndo(parent, "Delete Track");
            }

            var children = track.GetChildTracks();

            foreach (var child in children)
            {
                DeleteTrack(child);
            }

            DeleteRecordedAnimation(track);

            var clipsToDelete = new List <TimelineClip>(track.clips);

            foreach (var clip in clipsToDelete)
            {
                DeleteClip(clip);
            }
            RemoveTrack(track);

            TimelineUndo.PushDestroyUndo(this, this, track);

            return(true);
        }
 public static void SetGroup(this TrackAsset asset, GroupTrack group)
 {
     if (!(asset == null) && !(asset == group) && !(asset.parent == group))
     {
         if (group != null && asset.timelineAsset != group.timelineAsset)
         {
             throw new InvalidOperationException("Cannot assign to a group in a different timeline");
         }
         TimelineUndo.PushUndo(asset, "Reparent");
         TimelineAsset timelineAsset  = asset.timelineAsset;
         TrackAsset    trackAsset     = asset.parent as TrackAsset;
         TimelineAsset timelineAsset2 = asset.parent as TimelineAsset;
         if (trackAsset != null || timelineAsset2 != null)
         {
             TimelineUndo.PushUndo(asset.parent, "Reparent");
             if (timelineAsset2 != null)
             {
                 timelineAsset2.RemoveTrack(asset);
             }
             else
             {
                 trackAsset.RemoveSubTrack(asset);
             }
         }
         if (group == null)
         {
             TimelineUndo.PushUndo(timelineAsset, "Reparent");
             asset.parent = asset.timelineAsset;
             timelineAsset.AddTrackInternal(asset);
         }
         else
         {
             TimelineUndo.PushUndo(group, "Reparent");
             group.AddChild(asset);
         }
     }
 }