private TimelineClip CreateClipFromAsset(ScriptableObject playableAsset) { TimelineUndo.PushUndo(this, "Create Clip"); var newClip = CreateNewClipContainerInternal(); newClip.displayName = playableAsset.name; newClip.asset = playableAsset; IPlayableAsset iPlayableAsset = playableAsset as IPlayableAsset; if (iPlayableAsset != null) { var candidateDuration = iPlayableAsset.duration; if (!double.IsInfinity(candidateDuration) && candidateDuration > 0) { newClip.duration = Math.Min(Math.Max(candidateDuration, TimelineClip.kMinDuration), TimelineClip.kMaxTimeValue); } } try { OnCreateClip(newClip); } catch (Exception e) { Debug.LogError(e.Message, playableAsset); return(null); } return(newClip); }
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"); } if (!owner.supportsNotifications && typeof(INotification).IsAssignableFrom(type)) { throw new InvalidOperationException( "Markers implementing the INotification interface cannot be added on tracks that do not support notifications"); } 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; }
TrackAsset AllocateTrack(TrackAsset trackAssetParent, string trackName, Type trackType) { if (trackAssetParent != null && trackAssetParent.timelineAsset != this) { throw new InvalidOperationException("Addtrack cannot parent to a track not in the Timeline"); } if (!typeof(TrackAsset).IsAssignableFrom(trackType)) { throw new InvalidOperationException("Supplied type must be a track asset"); } var asset = (TrackAsset)CreateInstance(trackType); asset.name = trackName; const string createTrackUndoName = "Create Track"; PlayableAsset parent = trackAssetParent != null ? trackAssetParent as PlayableAsset : this; TimelineCreateUtilities.SaveAssetIntoObject(asset, parent); TimelineUndo.RegisterCreatedObjectUndo(asset, createTrackUndoName); TimelineUndo.PushUndo(parent, createTrackUndoName); if (trackAssetParent != null) { trackAssetParent.AddChild(asset); } else //TimelineAsset is the parent { AddTrackInternal(asset); } return(asset); }
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); }
public bool DeleteTrack(TrackAsset track) { bool result; if (track.timelineAsset != this) { result = false; } else { TrackAsset x = track.parent as TrackAsset; if (x != null) { } IEnumerable <TrackAsset> childTracks = track.GetChildTracks(); foreach (TrackAsset track2 in childTracks) { this.DeleteTrack(track2); } this.DeleteRecordingClip(track); List <TimelineClip> list = new List <TimelineClip>(track.clips); foreach (TimelineClip clip in list) { this.DeleteClip(clip); } this.RemoveTrack(track); TimelineUndo.PushDestroyUndo(this, this, track, "Delete Track"); result = true; } return(result); }
public bool DeleteClip(TimelineClip clip) { bool result; if (clip == null || clip.parentTrack == null) { result = false; } else if (this != clip.parentTrack.timelineAsset) { Debug.LogError("Cannot delete a clip from this timeline"); result = false; } else { if (clip.curves != null) { TimelineUndo.PushDestroyUndo(this, clip.parentTrack, clip.curves, "Delete Curves"); } if (clip.asset != null) { this.DeleteRecordedAnimation(clip); TimelineUndo.PushDestroyUndo(this, clip.parentTrack, clip.asset, "Delete Clip Asset"); } TrackAsset parentTrack = clip.parentTrack; parentTrack.RemoveClip(clip); parentTrack.CalculateExtrapolationTimes(); result = true; } return(result); }
private void DeleteRecordingClip(TrackAsset track) { AnimationTrack animationTrack = track as AnimationTrack; if (!(animationTrack == null) && !(animationTrack.animClip == null)) { TimelineUndo.PushDestroyUndo(this, track, animationTrack.animClip, "Delete Track"); } }
public bool Remove(ScriptableObject item, TimelineAsset timelineAsset, PlayableAsset thingToDirty) { if (!m_Objects.Contains(item)) return false; TimelineUndo.PushUndo(thingToDirty, "Delete Marker"); m_Objects.Remove(item); m_CacheDirty = true; TimelineUndo.PushDestroyUndo(timelineAsset, thingToDirty, item, "Delete Marker"); return true; }
/// <summary> /// Allows you to create a track and add it to the Timeline. /// </summary> /// <param name="type">The type of track to create. Must derive from TrackAsset.</param> /// <param name="parent">Track to parent to. This can be null.</param> /// <param name="name">Name to give the track.</param> /// <returns>The created track.</returns> /// <remarks> /// This method will throw an InvalidOperationException if the parent is not valid. The parent can be any GroupTrack, or a supported parent type of track. For example, this can be used to create override tracks in AnimationTracks. /// </remarks> public TrackAsset CreateTrack(Type type, TrackAsset parent, string name) { if (parent != null && parent.timelineAsset != this) { throw new InvalidOperationException("Addtrack cannot parent to a track not in the Timeline"); } if (!typeof(TrackAsset).IsAssignableFrom(type)) { throw new InvalidOperationException("Supplied type must be a track asset"); } if (parent != null) { if (!TimelineCreateUtilities.ValidateParentTrack(parent, type)) { throw new InvalidOperationException("Cannot assign a child of type " + type.Name + " to a parent of type " + parent.GetType().Name); } } var actualParent = parent != null ? parent as PlayableAsset : this; TimelineUndo.PushUndo(actualParent, "Create Track"); var baseName = name; if (string.IsNullOrEmpty(baseName)) { baseName = type.Name; #if UNITY_EDITOR baseName = UnityEditor.ObjectNames.NicifyVariableName(baseName); #endif } var trackName = baseName; if (parent != null) { trackName = TimelineCreateUtilities.GenerateUniqueActorName(parent.subTracksObjects, baseName); } else { trackName = TimelineCreateUtilities.GenerateUniqueActorName(trackObjects, baseName); } TrackAsset newTrack = AllocateTrack(parent, trackName, type); if (newTrack != null) { newTrack.name = trackName; TimelineCreateUtilities.SaveAssetIntoObject(newTrack, actualParent); } return(newTrack); }
void DeleteRecordedAnimation(TrackAsset track) { var animTrack = track as AnimationTrack; if (animTrack != null && animTrack.infiniteClip != null) { TimelineUndo.PushDestroyUndo(this, track, animTrack.infiniteClip); } if (track.curves != null) { TimelineUndo.PushDestroyUndo(this, track, track.curves); } }
internal TimelineClip CreateClipOfType(Type requestedType) { if (!ValidateClipType(requestedType)) throw new System.InvalidOperationException("Clips of type " + requestedType + " are not permitted on tracks of type " + GetType()); var playableAsset = CreateInstance(requestedType); if (playableAsset == null) { throw new System.InvalidOperationException("Could not create an instance of the ScriptableObject type " + requestedType.Name); } playableAsset.name = requestedType.Name; TimelineCreateUtilities.SaveAssetIntoObject(playableAsset, this); TimelineUndo.RegisterCreatedObjectUndo(playableAsset, "Create Clip"); return CreateClipFromAsset(playableAsset); }
/// <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); } }
private void DeleteRecordedAnimation(TimelineClip clip) { if (clip != null) { if (clip.curves != null) { TimelineUndo.PushDestroyUndo(this, clip.parentTrack, clip.curves, "Delete Parameters"); } if (clip.recordable) { AnimationPlayableAsset animationPlayableAsset = clip.asset as AnimationPlayableAsset; if (!(animationPlayableAsset == null) && !(animationPlayableAsset.clip == null)) { TimelineUndo.PushDestroyUndo(this, animationPlayableAsset, animationPlayableAsset.clip, "Delete Recording"); } } } }
/// <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); }
/// <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.parentTrack == null) { return(false); } if (this != clip.parentTrack.timelineAsset) { Debug.LogError("Cannot delete a clip from this timeline"); return(false); } TimelineUndo.PushUndo(clip.parentTrack, "Delete Clip"); if (clip.curves != null) { TimelineUndo.PushDestroyUndo(this, clip.parentTrack, 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.parentTrack, clip.asset); } } var clipParentTrack = clip.parentTrack; clipParentTrack.RemoveClip(clip); clipParentTrack.CalculateExtrapolationTimes(); return(true); }
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); }
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); } }
public static AnimationClip CreateAnimationClipForTrack(string name, TrackAsset track, bool isLegacy) { var timelineAsset = track != null ? track.timelineAsset : null; var trackFlags = track != null ? track.hideFlags : HideFlags.None; var curves = new AnimationClip { legacy = isLegacy, name = name, frameRate = timelineAsset == null ? TimelineAsset.EditorSettings.kDefaultFps : timelineAsset.editorSettings.fps }; SaveAssetIntoObject(curves, timelineAsset); curves.hideFlags = trackFlags & ~HideFlags.HideInHierarchy; // Never hide in hierarchy TimelineUndo.RegisterCreatedObjectUndo(curves, "Create Curves"); return(curves); }
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); } } }