예제 #1
0
        void DeleteRecordedAnimation(TimelineClip clip)
        {
            if (clip == null)
            {
                return;
            }

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

            if (!clip.recordable)
            {
                return;
            }

            AnimationPlayableAsset asset = clip.asset as AnimationPlayableAsset;

            if (asset == null || asset.clip == null)
            {
                return;
            }

            TimelineUndo.PushDestroyUndo(this, asset, asset.clip);
        }
        /// <summary>
        /// Tries to move a TimelineClip to a different track. Validates that the destination track can accept the clip before performing the move.
        /// Fails if the clip's PlayableAsset is null, the current and destination tracks are the same or the destination track cannot accept the clip.
        /// </summary>
        /// <param name="clip">Clip that is being moved</param>
        /// <param name="destinationTrack">Desired destination track</param>
        /// <returns>Returns true if the clip was successfully moved to the destination track, false otherwise. Also returns false if either argument is null</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="clip"/> or <paramref name="destinationTrack"/> are null</exception>
        public static bool TryMoveToTrack(this TimelineClip clip, TrackAsset destinationTrack)
        {
            if (clip == null)
            {
                throw new ArgumentNullException($"'this' argument for {nameof(TryMoveToTrack)} cannot be null.");
            }

            if (destinationTrack == null)
            {
                throw new ArgumentNullException("Cannot move TimelineClip to a null parent.");
            }

            TrackAsset parentTrack = clip.GetParentTrack();
            Object     asset       = clip.asset;

            // If the asset is null we cannot validate its type against the destination track
            if (asset == null)
            {
                return(false);
            }

            if (parentTrack != destinationTrack)
            {
                if (!destinationTrack.ValidateClipType(asset.GetType()))
                {
                    return(false);
                }

                MoveToTrack_Impl(clip, destinationTrack, asset, parentTrack);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Tries to move a TimelineClip to a different track. Validates that the destination track can accept the clip before performing the move.
        /// Fails if the clip's PlayableAsset is null, the current and destination tracks are the same or the destination track cannot accept the clip.
        /// </summary>
        /// <param name="clip">Clip that is being moved</param>
        /// <param name="destinationTrack">Desired destination track</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="clip"/> or <paramref name="destinationTrack"/> are null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the PlayableAsset in the TimelineClip is null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the current parent track and destination track are the same</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the destination track cannot hold tracks of the given type</exception>
        public static void MoveToTrack(this TimelineClip clip, TrackAsset destinationTrack)
        {
            if (clip == null)
            {
                throw new ArgumentNullException($"'this' argument for {nameof(MoveToTrack)} cannot be null.");
            }

            if (destinationTrack == null)
            {
                throw new ArgumentNullException("Cannot move TimelineClip to a null track.");
            }

            TrackAsset parentTrack = clip.GetParentTrack();
            Object     asset       = clip.asset;

            // If the asset is null we cannot validate its type against the destination track
            if (asset == null)
            {
                throw new InvalidOperationException("Cannot move a TimelineClip to a different track if the TimelineClip's PlayableAsset is null.");
            }

            if (parentTrack == destinationTrack)
            {
                throw new InvalidOperationException($"TimelineClip is already on {destinationTrack.name}.");
            }

            if (!destinationTrack.ValidateClipType(asset.GetType()))
            {
                throw new InvalidOperationException($"Track {destinationTrack.name} cannot contain clips of type {clip.GetType().Name}.");
            }

            MoveToTrack_Impl(clip, destinationTrack, asset, parentTrack);
        }
예제 #4
0
        /// <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);
        }