private static AnimationClip CloneAnimationClipIfRequired(AnimationClip clip, Object owner) { AnimationClip result; if (clip == null) { result = null; } else { string assetPath = AssetDatabase.GetAssetPath(clip); string assetPath2 = AssetDatabase.GetAssetPath(owner); bool flag = assetPath == assetPath2; if (flag) { AnimationClip animationClip = Object.Instantiate <AnimationClip>(clip); animationClip.set_name(AnimationTrackRecorder.GetUniqueRecordedClipName(owner, clip.get_name())); animationClip.set_hideFlags(clip.get_hideFlags()); if ((clip.get_hideFlags() & 52) != 52 && assetPath2.Length > 0) { TimelineHelpers.SaveAnimClipIntoObject(animationClip, owner); } EditorUtility.SetDirty(owner); clip = animationClip; } result = clip; } return(result); }
public static AnimationClip GetOrCreateClip(this AnimationTrack track) { if (track.infiniteClip == null && !track.inClipMode) { track.CreateInfiniteClip(AnimationTrackRecorder.GetUniqueRecordedClipName(track, AnimationTrackRecorder.kRecordClipDefaultName)); } return(track.infiniteClip); }
// Given a track, return the animation clip internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time) { if (trackAsset == null) { return(null); } AnimationTrack animTrack = trackAsset as AnimationTrack; if (animTrack != null && !animTrack.inClipMode) { return(animTrack.infiniteClip); } TimelineClip displayBackground; trackAsset.FindRecordingClipAtTime(time, out displayBackground); if (displayBackground != null) { if (displayBackground.recordable) { AnimationPlayableAsset asset = displayBackground.asset as AnimationPlayableAsset; if (asset != null) { return(asset.clip); } } else if (animTrack == null) { if (displayBackground.curves == null) { displayBackground.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(displayBackground.parentTrack, TimelineClip.kDefaultCurvesName)); } return(displayBackground.curves); } } else if (trackAsset.HasAnyAnimatableParameters()) { if (trackAsset.curves == null) { trackAsset.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(trackAsset.timelineAsset, TrackAsset.kDefaultCurvesName)); } return(trackAsset.curves); } return(null); }
static AnimationClip CloneAnimationClip(AnimationClip clip, Object owner) { if (clip == null) { return(null); } var newClip = Object.Instantiate(clip); newClip.name = AnimationTrackRecorder.GetUniqueRecordedClipName(owner, clip.name); SaveAnimClipIntoObject(newClip, owner); TimelineUndo.RegisterCreatedObjectUndo(newClip, "Create clip"); return(newClip); }
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 CreateCurvesOnDifferentOwner(TimelineClip clip, Object owner) { clip.curves = new AnimationClip { legacy = true, name = AnimationTrackRecorder.GetUniqueRecordedClipName(owner, TimelineClip.kDefaultCurvesName) }; var assetPath = AssetDatabase.GetAssetPath(owner); if (!string.IsNullOrEmpty(assetPath)) { TimelineHelpers.SaveAnimClipIntoObject(clip.curves, owner); EditorUtility.SetDirty(owner); AssetDatabase.ImportAsset(assetPath); AssetDatabase.Refresh(); } }
internal static void CreateCurvesIfRequired(TimelineClip clip, Object owner = null) { if (owner == null) { owner = clip.parentTrack; } if (clip.curves == null) { if (owner == clip.parentTrack) { clip.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(owner, TimelineClip.kDefaultCurvesName)); } else { CreateCurvesOnDifferentOwner(clip, owner); } } }
public static AnimationClip GetOrCreateClip(this TrackAsset track) { bool flag = false; AnimationTrack animationTrack = track as AnimationTrack; if (animationTrack != null) { flag = animationTrack.inClipMode; } if (track.animClip == null && !flag) { track.animClip = new AnimationClip(); track.animClip.set_name(AnimationTrackRecorder.GetUniqueRecordedClipName(track, AnimationTrackRecorder.kRecordClipDefaultName)); Undo.RegisterCreatedObjectUndo(track.animClip, "Create Track"); AnimationUtility.SetGenerateMotionCurves(track.animClip, true); TimelineHelpers.SaveAnimClipIntoObject(track.animClip, track); } return(track.animClip); }
internal static void CreateCurvesIfRequired(TimelineClip clip, TrackAsset parentTrack = null) { if (clip.curves == null) { if (parentTrack == null) { parentTrack = clip.parentTrack; } clip.AllocateAnimatedParameterCurves(); clip.curves.set_name(AnimationTrackRecorder.GetUniqueRecordedClipName(clip.parentTrack, AnimatedParameterExtensions.kDefaultClipName)); string assetPath = AssetDatabase.GetAssetPath(clip.parentTrack); if (!string.IsNullOrEmpty(assetPath)) { TimelineHelpers.SaveAnimClipIntoObject(clip.curves, clip.parentTrack); EditorUtility.SetDirty(clip.parentTrack); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(clip.parentTrack)); AssetDatabase.Refresh(); } } }
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 static string GetUniqueRecordedClipName(this ICurvesOwner curvesOwner) { return(AnimationTrackRecorder.GetUniqueRecordedClipName(curvesOwner.assetOwner, curvesOwner.defaultCurvesName)); }