Esempio n. 1
0
 private static void ShiftAnimationClip(AnimationClip clip, float amount)
 {
     if (!(clip == null))
     {
         EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(clip);
         EditorCurveBinding[] objectReferenceCurveBindings = AnimationUtility.GetObjectReferenceCurveBindings(clip);
         EditorCurveBinding[] array = curveBindings;
         for (int i = 0; i < array.Length; i++)
         {
             EditorCurveBinding editorCurveBinding = array[i];
             AnimationCurve     editorCurve        = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);
             editorCurve.set_keys(AnimationTrackRecorder.ShiftKeys(editorCurve.get_keys(), amount));
             AnimationUtility.SetEditorCurve(clip, editorCurveBinding, editorCurve);
         }
         EditorCurveBinding[] array2 = objectReferenceCurveBindings;
         for (int j = 0; j < array2.Length; j++)
         {
             EditorCurveBinding        editorCurveBinding2 = array2[j];
             ObjectReferenceKeyframe[] array3 = AnimationUtility.GetObjectReferenceCurve(clip, editorCurveBinding2);
             array3 = AnimationTrackRecorder.ShiftObjectKeys(array3, amount);
             AnimationUtility.SetObjectReferenceCurve(clip, editorCurveBinding2, array3);
         }
         EditorUtility.SetDirty(clip);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 8
0
 public void FinalizeRecording(TimelineWindow.TimelineState state)
 {
     for (int num = 0; num != this.m_ProcessedClips.Count; num++)
     {
         AnimationTrackRecorder.ProcessTemporaryKeys(this.m_ProcessedClips[num]);
     }
     this.m_RefreshState |= this.m_TracksToProcess.Any <TrackAsset>();
     this.m_TracksToProcess.Clear();
     if (this.m_ProcessedClips.Count > 0 || this.m_RefreshState)
     {
         state.GetWindow().RebuildGraphIfNecessary(false);
     }
     state.RebindAnimators(this.m_RebindList);
     if (this.m_ProcessedClips.Count > 0 || this.m_RefreshState)
     {
         state.EvaluateImmediate();
     }
 }
        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();
         }
     }
 }
Esempio n. 12
0
 private static void ProcessTemporaryKeys(AnimationClip clip)
 {
     if (!(clip == null))
     {
         bool flag = false;
         EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(clip);
         EditorCurveBinding[] array         = curveBindings;
         for (int i = 0; i < array.Length; i++)
         {
             EditorCurveBinding editorCurveBinding = array[i];
             if (!editorCurveBinding.propertyName.Contains("LocalRotation.w"))
             {
                 EditorCurveBinding binding = RotationCurveInterpolation.RemapAnimationBindingForRotationCurves(editorCurveBinding, clip);
                 flag |= AnimationTrackRecorder.ProcessCurveBinding(clip, binding);
             }
         }
         if (flag)
         {
             EditorUtility.SetDirty(clip);
         }
     }
 }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 public static string GetUniqueRecordedClipName(this ICurvesOwner curvesOwner)
 {
     return(AnimationTrackRecorder.GetUniqueRecordedClipName(curvesOwner.assetOwner, curvesOwner.defaultCurvesName));
 }
Esempio n. 15
0
        public static void SetStart(TimelineClip clip, double time)
        {
            var supportsClipIn  = clip.SupportsClipIn();
            var supportsPadding = TimelineUtility.IsRecordableAnimationClip(clip);

            // treat empty recordable clips as not supporting clip in (there are no keys to modify)
            if (supportsPadding && (clip.animationClip == null || clip.animationClip.empty))
            {
                supportsClipIn = false;
            }

            if (supportsClipIn && !supportsPadding)
            {
                var minStart = clip.FromLocalTimeUnbound(0.0);
                if (time < minStart)
                {
                    time = minStart;
                }
            }

            var maxStart = clip.end - TimelineClip.kMinDuration;

            if (time > maxStart)
            {
                time = maxStart;
            }

            var timeOffset = time - clip.start;
            var duration   = clip.duration - timeOffset;

            if (supportsClipIn)
            {
                if (supportsPadding)
                {
                    double clipInGlobal = clip.clipIn / clip.timeScale;
                    double keyShift     = -timeOffset;
                    if (timeOffset < 0) // left drag, eliminate clipIn before shifting
                    {
                        double clipInDelta = Math.Max(-clipInGlobal, timeOffset);
                        keyShift     = -Math.Min(0, timeOffset - clipInDelta);
                        clip.clipIn += clipInDelta * clip.timeScale;
                    }
                    else if (timeOffset > 0) // right drag, elimate padding in animation clip before adding clip in
                    {
                        var    clipInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip);
                        double keyDelta = clip.FromLocalTimeUnbound(clipInfo.keyTimes.Min()) - clip.start;
                        keyShift     = -Math.Max(0, Math.Min(timeOffset, keyDelta));
                        clip.clipIn += Math.Max(timeOffset + keyShift, 0) * clip.timeScale;
                    }
                    if (keyShift != 0)
                    {
                        AnimationTrackRecorder.ShiftAnimationClip(clip.animationClip, (float)(keyShift * clip.timeScale));
                    }
                }
                else
                {
                    clip.clipIn += timeOffset * clip.timeScale;
                }
            }

            clip.start    = time;
            clip.duration = duration;
            clip.ConformEaseValues();
        }
Esempio n. 16
0
        public AnimationClip PrepareTrack(TrackAsset track, TimelineWindow.TimelineState state, GameObject gameObject, out double startTime)
        {
            AnimationTrack animationTrack = (AnimationTrack)track;
            AnimationClip  result;

            if (!animationTrack.inClipMode)
            {
                AnimationClip orCreateClip = animationTrack.GetOrCreateClip();
                startTime = (double)orCreateClip.get_frameRate() * state.time;
                if (!this.m_TracksToProcess.Contains(animationTrack))
                {
                    this.m_TracksToProcess.Add(animationTrack);
                }
                this.m_RebindList.Add(gameObject);
                if (orCreateClip.get_empty())
                {
                    animationTrack.openClipTimeOffset        = 0.0;
                    animationTrack.openClipPreExtrapolation  = TimelineClip.ClipExtrapolation.Hold;
                    animationTrack.openClipPostExtrapolation = TimelineClip.ClipExtrapolation.Hold;
                }
                result = orCreateClip;
            }
            else
            {
                TimelineClip timelineClip = AnimationTrackRecorder.GetRecordingClipForTrack(track, state);
                if (timelineClip == null)
                {
                    timelineClip = track.FindRecordingClipAtTime(state.time);
                }
                List <TimelineClip> list = (from x in track.clips
                                            where x.start <= state.time && x.end >= state.time
                                            select x).ToList <TimelineClip>();
                if (timelineClip == null)
                {
                    if (list.Count != 0)
                    {
                        if (list.Count > 0)
                        {
                            if (list.Any((TimelineClip x) => x.recordable))
                            {
                                goto IL_12A;
                            }
                        }
                        Debug.LogWarning("Cannot record on top of an imported animation clip");
                        startTime = -1.0;
                        result    = null;
                        return(result);
                    }
IL_12A:
                    timelineClip       = AnimationTrackRecorder.AddRecordableClip(track, state);
                    timelineClip.start = state.time;
                    this.m_RebindList.Add(gameObject);
                }
                AnimationClip animationClip = timelineClip.animationClip;
                double        num           = state.time - timelineClip.start;
                if (num < 0.0)
                {
                    Undo.RegisterCompleteObjectUndo(animationClip, "Record Key");
                    TimelineUndo.PushUndo(track, "Prepend Key");
                    AnimationTrackRecorder.ShiftAnimationClip(animationClip, (float)(-(float)num));
                    timelineClip.start     = state.time;
                    timelineClip.duration += -num;
                    num = 0.0;
                    this.m_RefreshState = true;
                }
                this.m_ClipTime         = num;
                this.recordClip         = timelineClip;
                startTime               = (double)TimeUtility.ToFrames(this.recordClip.ToLocalTimeUnbound(state.time), (double)animationClip.get_frameRate());
                this.m_needRebuildRects = animationClip.get_empty();
                result = animationClip;
            }
            return(result);
        }