/// <summary> /// Creates a marker track for the TimelineAsset. /// </summary> /// In the editor, the marker track appears under the Timeline ruler. /// <remarks> /// This track is always bound to the GameObject that contains the PlayableDirector component for the current timeline. /// The marker track is created the first time this method is called. If the marker track is already created, this method does nothing. /// </remarks> public void CreateMarkerTrack() { if (m_MarkerTrack == null) { m_MarkerTrack = CreateInstance <MarkerTrack>(); TimelineCreateUtilities.SaveAssetIntoObject(m_MarkerTrack, this); m_MarkerTrack.parent = this; m_MarkerTrack.name = "Markers"; // This name will show up in the bindings list if it contains signals Invalidate(); } }
/// <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); }
/// <summary> /// Creates an AnimationClip that stores the data for an infinite track. /// </summary> /// <remarks> /// If an infiniteClip already exists, this method produces no result, even if you provide a different value /// for infiniteClipName. /// </remarks> /// <remarks> /// This method can't create an infinite clip for an AnimationTrack that contains one or more Timeline clips. /// Use AnimationTrack.inClipMode to determine whether it is possible to create an infinite clip on an AnimationTrack. /// </remarks> /// <remarks> /// When used from the editor, this method attempts to save the created infinite clip to the TimelineAsset. /// The TimelineAsset must already exist in the AssetDatabase to save the infinite clip. If the TimelineAsset /// does not exist, the infinite clip is still created but it is not saved. /// </remarks> /// <param name="infiniteClipName"> /// The name of the AnimationClip to create. /// This method does not ensure unique names. If you want a unique clip name, you must provide one. /// See ObjectNames.GetUniqueName for information on a method that creates unique names. /// </param> public void CreateInfiniteClip(string infiniteClipName) { if (inClipMode) { Debug.LogWarning("CreateInfiniteClip cannot create an infinite clip for an AnimationTrack that contains one or more Timeline Clips."); return; } if (m_InfiniteClip != null) { return; } m_InfiniteClip = TimelineCreateUtilities.CreateAnimationClipForTrack(string.IsNullOrEmpty(infiniteClipName) ? k_DefaultInfiniteClipName : infiniteClipName, this, false); }
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); }
internal override void OnCreateClipFromAsset(Object asset, TimelineClip clip) { AnimationClip animationClip = asset as AnimationClip; if (animationClip != null) { if (animationClip.legacy) { throw new InvalidOperationException("Legacy Animation Clips are not supported"); } AnimationPlayableAsset animationPlayableAsset = ScriptableObject.CreateInstance <AnimationPlayableAsset>(); TimelineCreateUtilities.SaveAssetIntoObject(animationPlayableAsset, this); animationPlayableAsset.clip = animationClip; clip.asset = animationPlayableAsset; this.AssignAnimationClip(clip, animationClip); } }
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); } } PlayableAsset masterAsset = (!(parent != null)) ? this : parent; string text = name; if (string.IsNullOrEmpty(text)) { text = type.Name; } string text2; if (parent != null) { text2 = TimelineCreateUtilities.GenerateUniqueActorName(parent.subTracksObjects, text); } else { text2 = TimelineCreateUtilities.GenerateUniqueActorName(this.trackObjects, text); } TrackAsset trackAsset = this.AllocateTrack(parent, text2, type); if (trackAsset != null) { trackAsset.name = text2; TimelineCreateUtilities.SaveAssetIntoObject(trackAsset, masterAsset); } return(trackAsset); }
/// <summary> /// Creates a TimelineClip, AnimationPlayableAsset and an AnimationClip. Use this clip to record in a timeline. /// </summary> /// <remarks> /// When used from the editor, this method attempts to save the created recordable clip to the TimelineAsset. /// The TimelineAsset must already exist in the AssetDatabase to save the recordable clip. If the TimelineAsset /// does not exist, the recordable clip is still created but it is not saved. /// </remarks> /// <param name="animClipName"> /// The name of the AnimationClip to create. /// This method does not ensure unique names. If you want a unique clip name, you must provide one. /// See ObjectNames.GetUniqueName for information on a method that creates unique names. /// </param> /// <returns> /// Returns a new TimelineClip with an AnimationPlayableAsset asset attached. /// </returns> public TimelineClip CreateRecordableClip(string animClipName) { var clip = TimelineCreateUtilities.CreateAnimationClipForTrack(string.IsNullOrEmpty(animClipName) ? k_DefaultRecordableClipName : animClipName, this, false); var timelineClip = CreateClip(clip); timelineClip.displayName = animClipName; timelineClip.recordable = true; timelineClip.start = 0; timelineClip.duration = 1; var apa = timelineClip.asset as AnimationPlayableAsset; if (apa != null) { apa.removeStartOffset = false; } return(timelineClip); }
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 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); }