public static void SaveSequence(TimelineAsset timeline, string path) { string assetPath = AssetDatabase.GetAssetPath(timeline); if (assetPath.Length == 0) { AssetDatabase.CreateAsset(timeline, AssetDatabase.GenerateUniqueAssetPath(path + "/" + timeline.get_name() + ".playable")); } foreach (TrackAsset current in timeline.tracks) { string assetPath2 = AssetDatabase.GetAssetPath(current); if (assetPath2.Length == 0) { TimelineCreateUtilities.SaveAssetIntoObject(current, timeline); TimelineClip[] clips = current.clips; for (int i = 0; i < clips.Length; i++) { TimelineClip timelineClip = clips[i]; string assetPath3 = AssetDatabase.GetAssetPath(timelineClip.asset); if (assetPath3.Length == 0) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, current); } if (timelineClip.curves != null) { string assetPath4 = AssetDatabase.GetAssetPath(timelineClip.curves); if (assetPath4.Length == 0) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.curves, current); } } } } } }
private static void AddAssetOnTrack(Type typeOfClip, TrackAsset track, ITimelineState state) { state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent) { ObjectSelector.get_get().Show(null, typeOfClip, null, false); ObjectSelector.get_get().objectSelectorID = 0; ObjectSelector.get_get().set_searchFilter(""); return(true); }); state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent) { bool result; if (currentEvent.get_commandName() == "ObjectSelectorClosed") { AnimationTrack animationTrack = track as AnimationTrack; if (animationTrack && !animationTrack.inClipMode) { animationTrack.ConvertToClipMode(); } TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(EditorGUIUtility.GetObjectPickerObject(), track, istate, TimelineHelpers.sInvalidMousePosition); if (timelineClip != null && timelineClip.asset != null) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, track); } result = true; } else { result = false; } return(result); }); }
public static void ConvertToClipMode(this AnimationTrack track) { if (track.CanConvertToClipMode()) { TimelineUndo.PushUndo(track, "Convert To Clip"); if (!track.animClip.get_empty()) { TimelineUndo.PushUndo(track.animClip, "Convert To Clip"); float num = AnimationClipCurveCache.Instance.GetCurveInfo(track.animClip).keyTimes.FirstOrDefault <float>(); track.animClip.ShiftBySeconds(-num); TimelineClip timelineClip = track.CreateClipFromAsset(track.animClip); TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, track); timelineClip.start = (double)num; timelineClip.preExtrapolationMode = track.openClipPreExtrapolation; timelineClip.postExtrapolationMode = track.openClipPostExtrapolation; timelineClip.recordable = true; if (Math.Abs(timelineClip.duration) < 1.4012984643248171E-45) { timelineClip.duration = 1.0; } AnimationPlayableAsset animationPlayableAsset = timelineClip.asset as AnimationPlayableAsset; if (animationPlayableAsset) { animationPlayableAsset.position = track.openClipOffsetPosition; animationPlayableAsset.rotation = track.openClipOffsetRotation; track.openClipOffsetPosition = Vector3.get_zero(); track.openClipOffsetRotation = Quaternion.get_identity(); } track.CalculateExtrapolationTimes(); } track.animClip = null; EditorUtility.SetDirty(track); } }
internal static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, PlayableDirector director, PlayableAsset assetOwner) { var subtracks = source.GetChildTracks(); foreach (var sub in subtracks) { var newSub = TimelineHelpers.Clone(duplicate, sub, director, assetOwner); duplicate.AddChild(newSub); RecursiveSubtrackClone(sub, newSub, director, assetOwner); // Call the custom editor on Create var customEditor = CustomTimelineEditorCache.GetTrackEditor(newSub); try { customEditor.OnCreate(newSub, sub); } catch (Exception e) { Debug.LogException(e); } // registration has to happen AFTER recursion TimelineUndo.RegisterCreatedObjectUndo(newSub, "Duplicate"); TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner); } }
private static void AddSubTrack(ITimelineState state, Type trackOfType, string trackName, TrackAsset track) { TrackAsset childAsset = state.timeline.CreateTrack(trackOfType, track, trackName); TimelineCreateUtilities.SaveAssetIntoObject(childAsset, track); track.SetCollapsed(false); state.Refresh(); }
static void AddSubTrack(WindowState state, Type trackOfType, string trackName, TrackAsset track) { var subAnimationTrack = state.editSequence.asset.CreateTrack(trackOfType, track, trackName); TimelineCreateUtilities.SaveAssetIntoObject(subAnimationTrack, track); track.SetCollapsed(false); state.Refresh(); }
private static void SaveCloneToOriginalAsset(Object original, Object clone) { string assetPath = AssetDatabase.GetAssetPath(original); Object @object = AssetDatabase.LoadAssetAtPath <Object>(assetPath); if (@object != null) { TimelineCreateUtilities.SaveAssetIntoObject(clone, @object); EditorUtility.SetDirty(@object); } }
static void SaveCloneToAsset(Object clone, Object newOwner) { var containerPath = AssetDatabase.GetAssetPath(newOwner); var containerAsset = AssetDatabase.LoadAssetAtPath <Object>(containerPath); if (containerAsset != null) { TimelineCreateUtilities.SaveAssetIntoObject(clone, containerAsset); EditorUtility.SetDirty(containerAsset); } }
static void AddMarkerToParent(ScriptableObject marker, TrackAsset parent) { TimelineCreateUtilities.SaveAssetIntoObject(marker, parent); TimelineUndo.RegisterCreatedObjectUndo(marker, "Duplicate Marker"); TimelineUndo.PushUndo(parent, "Duplicate Marker"); if (parent != null) { parent.AddMarker(marker); ((IMarker)marker).Initialize(parent); } }
internal static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, PlayableDirector director) { List <TrackAsset> subTracks = source.subTracks; foreach (TrackAsset current in subTracks) { TrackAsset trackAsset = TimelineHelpers.Clone(duplicate, current, director); duplicate.AddChild(trackAsset); TrackExtensions.RecursiveSubtrackClone(current, trackAsset, director); Undo.RegisterCreatedObjectUndo(trackAsset, "Duplicate"); TimelineCreateUtilities.SaveAssetIntoObject(trackAsset, source); } }
internal static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, PlayableDirector director, PlayableAsset assetOwner) { var subtracks = source.GetChildTracks(); foreach (var sub in subtracks) { var newSub = TimelineHelpers.Clone(duplicate, sub, director, assetOwner); duplicate.AddChild(newSub); RecursiveSubtrackClone(sub, newSub, director, assetOwner); // registration has to happen AFTER recursion TimelineUndo.RegisterCreatedObjectUndo(newSub, "Duplicate"); TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner); } }
internal static bool Duplicate(this TrackAsset track, PlayableDirector director, TimelineAsset destinationTimeline = null) { bool result; if (track == null) { result = false; } else { if (destinationTimeline == track.timelineAsset) { destinationTimeline = null; } TimelineAsset timelineAsset = track.parent as TimelineAsset; TrackAsset trackAsset = track.parent as TrackAsset; if (timelineAsset == null && trackAsset == null) { Debug.LogWarning("Cannot duplicate track because it is not parented to known type"); result = false; } else { PlayableAsset playableAsset = destinationTimeline ?? track.parent; TrackAsset trackAsset2 = TimelineHelpers.Clone(playableAsset, track, director); TrackExtensions.RecursiveSubtrackClone(track, trackAsset2, director); Undo.RegisterCreatedObjectUndo(trackAsset2, "Duplicate"); TimelineCreateUtilities.SaveAssetIntoObject(trackAsset2, playableAsset); TimelineUndo.PushUndo(playableAsset, "Duplicate"); if (destinationTimeline != null) { destinationTimeline.AddTrackInternal(trackAsset2); } else if (timelineAsset != null) { TrackExtensions.ReparentTracks(new List <TrackAsset> { trackAsset2 }, timelineAsset, track, false); } else { trackAsset.AddChildAfter(trackAsset2, track); } result = true; } } return(result); }
internal static TimelineClip Clone(TimelineClip clip, PlayableDirector director, PlayableAsset newOwner) { var editorClip = EditorClipFactory.GetEditorClip(clip); // Workaround for Clips not being unity object, assign it to a editor clip wrapper, clone it, and pull the clip back out var newClip = Object.Instantiate(editorClip).clip; // perform fix ups for what Instantiate cannot properly detect SelectionManager.Remove(newClip); newClip.parentTrack = null; newClip.curves = null; // instantiate might copy the reference, we need to clear it // curves are explicitly owned by the clip if (clip.curves != null) { newClip.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(newOwner, clip.curves.name)); EditorUtility.CopySerialized(clip.curves, newClip.curves); TimelineCreateUtilities.SaveAssetIntoObject(newClip.curves, newOwner); } ScriptableObject playableAsset = newClip.asset as ScriptableObject; if (playableAsset != null && newClip.asset is IPlayableAsset) { var clone = CloneReferencedPlayableAsset(playableAsset, director); SaveCloneToAsset(clone, newOwner); newClip.asset = clone; // special case to make the name match the recordable clips, but only if they match on the original clip var originalRecordedAsset = clip.asset as AnimationPlayableAsset; if (clip.recordable && originalRecordedAsset != null && originalRecordedAsset.clip != null) { AnimationPlayableAsset clonedAnimationAsset = clone as AnimationPlayableAsset; if (clonedAnimationAsset != null && clonedAnimationAsset.clip != null) { clonedAnimationAsset.clip = CloneAnimationClip(originalRecordedAsset.clip, newOwner); if (clip.displayName == originalRecordedAsset.clip.name && newClip.recordable) { clonedAnimationAsset.name = clonedAnimationAsset.clip.name; newClip.displayName = clonedAnimationAsset.name; } } } } return(newClip); }
static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, IExposedPropertyTable sourceTable, IExposedPropertyTable destTable, PlayableAsset assetOwner) { var subtracks = source.GetChildTracks(); foreach (var sub in subtracks) { var newSub = TimelineHelpers.Clone(duplicate, sub, sourceTable, destTable, assetOwner); duplicate.AddChild(newSub); RecursiveSubtrackClone(sub, newSub, sourceTable, destTable, assetOwner); // Call the custom editor on Create var customEditor = CustomTimelineEditorCache.GetTrackEditor(newSub); customEditor.OnCreate_Safe(newSub, sub); // registration has to happen AFTER recursion TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner); TimelineUndo.RegisterCreatedObjectUndo(newSub, L10n.Tr("Duplicate")); } }
static void SaveCloneToAsset(Object clone, Object newOwner) { if (newOwner == null) { return; } var containerPath = AssetDatabase.GetAssetPath(newOwner); var containerAsset = AssetDatabase.LoadAssetAtPath <Object>(containerPath); if (containerAsset != null) { TimelineCreateUtilities.SaveAssetIntoObject(clone, containerAsset); EditorUtility.SetDirty(containerAsset); } else { clone.hideFlags |= newOwner.hideFlags & HideFlags.DontSave; } }
public static TimelineClip CreateClipOnTrack(Type playableAssetType, TrackAsset parentTrack, ITimelineState state, Vector2 mousePosition) { TimelineClip result; if (!typeof(IPlayableAsset).IsAssignableFrom(playableAssetType) || !typeof(ScriptableObject).IsAssignableFrom(playableAssetType)) { result = null; } else { ScriptableObject scriptableObject = ScriptableObject.CreateInstance(playableAssetType); if (scriptableObject == null) { throw new InvalidOperationException("Could not create an instance of the ScriptableObject type " + playableAssetType.Name); } scriptableObject.set_name(playableAssetType.Name); TimelineCreateUtilities.SaveAssetIntoObject(scriptableObject, parentTrack); result = TimelineHelpers.CreateClipOnTrack(scriptableObject, parentTrack, state, mousePosition); } return(result); }
public static TimelineClip AddRecordableClip(TrackAsset parentTrack, TimelineWindow.TimelineState state) { TimelineAsset timeline = state.timeline; TimelineClip result; if (timeline == null) { Debug.LogError("Parent Track needs to be bound to an asset to add a recordable"); result = null; } else { AnimationClip animationClip = new AnimationClip(); animationClip.set_name(AnimationTrackRecorder.GetUniqueRecordedClipName(parentTrack, AnimationTrackRecorder.kRecordClipDefaultName)); animationClip.set_frameRate(state.frameRate); AnimationUtility.SetGenerateMotionCurves(animationClip, true); Undo.RegisterCreatedObjectUndo(animationClip, "Create Clip"); TimelineHelpers.SaveAnimClipIntoObject(animationClip, parentTrack); TimelineClip timelineClip = parentTrack.CreateClipFromAsset(animationClip); if (timelineClip != null) { timelineClip.recordable = true; timelineClip.displayName = animationClip.get_name(); timelineClip.timeScale = 1.0; timelineClip.start = 0.0; timelineClip.duration = 0.0; timelineClip.mixInCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); timelineClip.mixOutCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f); timelineClip.preExtrapolationMode = TimelineClip.ClipExtrapolation.Hold; timelineClip.postExtrapolationMode = TimelineClip.ClipExtrapolation.Hold; TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, parentTrack); state.Refresh(); } result = timelineClip; } return(result); }
public DragAndDropVisualMode HandleObjectDrop(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos) { DragAndDropVisualMode result; if (!perform) { List <Object> list = new List <Object>(); if (DragAndDrop.get_objectReferences().Any <Object>()) { list.AddRange(DragAndDrop.get_objectReferences()); using (List <Object> .Enumerator enumerator = list.GetEnumerator()) { while (enumerator.MoveNext()) { Object o = enumerator.Current; TrackType[] trackTypeHandle = TimelineHelpers.GetTrackTypeHandle(o.GetType()); if (!trackTypeHandle.Any <TrackType>() || trackTypeHandle.Any((TrackType t) => !TimelineDragging.ValidateObjectDrop(o))) { result = 0; return(result); } } } result = 1; } else if (DragAndDrop.get_paths().Any <string>()) { TimelineGroupGUI timelineGroupGUI = targetItem as TimelineGroupGUI; if (timelineGroupGUI == null) { result = 1; } else if (timelineGroupGUI.track == null) { result = 0; } else { TrackType tt = TimelineHelpers.TrackTypeFromType(timelineGroupGUI.track.GetType()); string[] paths = DragAndDrop.get_paths(); for (int i = 0; i < paths.Length; i++) { string text = paths[i]; list.AddRange(AssetDatabase.LoadAllAssetsAtPath(text)); } bool flag = (from o in list where o != null select o).Any((Object o) => TimelineHelpers.IsTypeSupportedByTrack(tt, o.GetType())); result = ((!flag) ? 0 : 1); } } else { result = 0; } } else { List <Object> list2 = new List <Object>(); list2.AddRange(DragAndDrop.get_objectReferences()); TrackAsset trackAsset = null; TimelineGroupGUI timelineGroupGUI2 = (TimelineGroupGUI)targetItem; if (targetItem != null && timelineGroupGUI2.track != null) { trackAsset = timelineGroupGUI2.track; } Vector2 mousePosition = Event.get_current().get_mousePosition(); foreach (Object current in list2) { if (!(current == null)) { if (current is TimelineAsset) { if (TimelineHelpers.IsCircularRef(this.m_Timeline, current as TimelineAsset)) { Debug.LogError("Cannot add " + current.get_name() + " to the sequence because it would cause a circular reference"); continue; } TimelineAsset timelineAsset = current as TimelineAsset; foreach (TrackAsset current2 in timelineAsset.tracks) { if (current2.mediaType == TimelineAsset.MediaType.Group) { this.m_Timeline.AddTrackInternal(current2); } } this.m_Window.state.Refresh(); EditorUtility.SetDirty(this.m_Timeline); } else if (current is TrackAsset) { this.m_Timeline.AddTrackInternal((TrackAsset)current); } else { TrackType trackType = null; TrackAsset trackAsset2 = null; TrackType[] trackTypeHandle2 = TimelineHelpers.GetTrackTypeHandle(current.GetType()); if (trackAsset != null) { TrackType[] array = trackTypeHandle2; for (int j = 0; j < array.Length; j++) { TrackType trackType2 = array[j]; if (trackAsset.GetType() == trackType2.trackType) { trackType = trackType2; break; } } } if (trackType == null) { if (trackTypeHandle2.Length == 1) { trackType = trackTypeHandle2[0]; } else if (trackTypeHandle2.Length > 1) { trackType = this.ResolveTypeAmbiguity(trackTypeHandle2); } } if (trackType == null) { continue; } if (!TimelineDragging.ValidateObjectDrop(current)) { continue; } if (trackAsset != null && trackAsset.GetType() == trackType.trackType) { trackAsset2 = trackAsset; } if (trackAsset2 == null) { trackAsset2 = this.m_Window.AddTrack(trackType.trackType, null, string.Empty); } if (trackAsset2 == null) { result = 0; return(result); } Object @object = TimelineDragging.TransformObjectBeingDroppedAccordingToTrackRules(trackAsset2, current); if (@object == null) { continue; } TimelineUndo.PushUndo(trackAsset2, "Create Clip"); AnimationTrack animationTrack = trackAsset2 as AnimationTrack; if (animationTrack != null) { animationTrack.ConvertToClipMode(); } TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(@object, trackAsset2, this.m_Window.state, mousePosition); if (timelineClip != null) { float num = this.m_Window.state.TimeToPixel(1.0) - this.m_Window.state.TimeToPixel(0.0); mousePosition.x += (float)timelineClip.duration * num; if (timelineClip.asset is ScriptableObject) { string assetPath = AssetDatabase.GetAssetPath(timelineClip.asset); if (assetPath.Length == 0) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, trackAsset2); } } TimelineDragging.FrameClips(this.m_Window.state); trackAsset2.SetCollapsed(false); } } this.m_Window.state.Refresh(); EditorUtility.SetDirty(this.m_Timeline); } } result = 1; } return(result); }
internal static TrackAsset Duplicate(this TrackAsset track, PlayableDirector director, TimelineAsset destinationTimeline = null) { if (track == null) { return(null); } // if the destination is us, clear to avoid bad parenting (case 919421) if (destinationTimeline == track.timelineAsset) { destinationTimeline = null; } var timelineParent = track.parent as TimelineAsset; var trackParent = track.parent as TrackAsset; if (timelineParent == null && trackParent == null) { Debug.LogWarning("Cannot duplicate track because it is not parented to known type"); return(null); } // Determine who the final parent is. If we are pasting into another track, it's always the timeline. // Otherwise it's the original parent PlayableAsset finalParent = destinationTimeline != null ? destinationTimeline : track.parent; // grab the list of tracks to generate a name from (923360) to get the list of names // no need to do this part recursively var finalTrackParent = finalParent as TrackAsset; var finalTimelineAsset = finalParent as TimelineAsset; var otherTracks = (finalTimelineAsset != null) ? finalTimelineAsset.trackObjects : finalTrackParent.subTracksObjects; // Important to create the new objects before pushing the original undo, or redo breaks the // sequence var newTrack = TimelineHelpers.Clone(finalParent, track, director, finalParent); newTrack.name = TimelineCreateUtilities.GenerateUniqueActorName(otherTracks, newTrack.name); RecursiveSubtrackClone(track, newTrack, director, finalParent); TimelineUndo.RegisterCreatedObjectUndo(newTrack, "Duplicate"); TimelineCreateUtilities.SaveAssetIntoObject(newTrack, finalParent); TimelineUndo.PushUndo(finalParent, "Duplicate"); if (destinationTimeline != null) // other timeline { destinationTimeline.AddTrackInternal(newTrack); } else if (timelineParent != null) // this timeline, no parent { ReparentTracks(new List <TrackAsset> { newTrack }, timelineParent, timelineParent.GetRootTracks().Last(), false); } else // this timeline, with parent { trackParent.AddChild(newTrack); } // Call the custom editor. this check prevents the call when copying to the clipboard if (destinationTimeline == null || destinationTimeline == TimelineEditor.inspectedAsset) { var customEditor = CustomTimelineEditorCache.GetTrackEditor(newTrack); try { customEditor.OnCreate(newTrack, track); } catch (Exception e) { Debug.LogException(e); } } return(newTrack); }