double ToGlobalTime(float localTime)
 {
     if (m_Clip != null)
     {
         return(Math.Max(0, m_Clip.FromLocalTimeUnbound(localTime)));
     }
     return(Math.Max(0, m_ClipData.start + localTime));
 }
Exemple #2
0
        public static double GetClipAssetEndTime(TimelineClip clip)
        {
            var d = GetLoopDuration(clip);

            if (d < double.MaxValue)
            {
                d = clip.FromLocalTimeUnbound(d);
            }

            return(d);
        }
Exemple #3
0
        public static IEnumerable <float> GetClipKeyTimes(TimelineClip clip)
        {
            if (clip == null || clip.animationClip == null || clip.animationClip.empty)
            {
                return(new float[0]);
            }

            return(AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip).keyTimes.
                   Select(k => (float)clip.FromLocalTimeUnbound(k)). // convert to sequence time
                   Where(k => k >= clip.start && k <= clip.end));    // remove non visible keys
        }
        public static IEnumerable <float> GetClipKeyTimes(TimelineClip clip)
        {
            IEnumerable <float> result;

            if (clip == null || clip.animationClip == null || clip.animationClip.get_empty())
            {
                result = new float[0];
            }
            else
            {
                result = from k in AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip).keyTimes
                         select(float) clip.FromLocalTimeUnbound((double)k) into k
                             where (double)k >= clip.start && (double)k <= clip.end
                         select k;
            }
            return(result);
        }
Exemple #5
0
        static HashSet <double> GetKeyTimes(UnityEngine.Object target, IEnumerable <PropertyModification> modifications, WindowState state)
        {
            var keyTimes = new HashSet <double>();

            AnimationClip animationClip;
            double        keyTime;
            bool          inRange;

            GetClipAndRelativeTime(target, state, out animationClip, out keyTime, out inRange);
            if (animationClip == null)
            {
                return(keyTimes);
            }

            var component     = target as Component;
            var playableAsset = target as IPlayableAsset;
            var info          = AnimationClipCurveCache.Instance.GetCurveInfo(animationClip);

            TimelineClip clip = null;

            if (component != null)
            {
                GetTrackForGameObject(component.gameObject, state).FindRecordingClipAtTime(state.editSequence.time, out clip);
            }
            else if (playableAsset != null)
            {
                clip = FindClipWithAsset(state.editSequence.asset, playableAsset);
            }

            foreach (var mod in modifications)
            {
                EditorCurveBinding temp;
                if (HasBinding(target, mod, animationClip, out temp))
                {
                    IEnumerable <double> keys = new HashSet <double>();
                    if (temp.isPPtrCurve)
                    {
                        var curve = info.GetObjectCurveForBinding(temp);
                        if (curve != null)
                        {
                            keys = curve.Select(x => (double)x.time);
                        }
                    }
                    else
                    {
                        var curve = info.GetCurveForBinding(temp);
                        if (curve != null)
                        {
                            keys = curve.keys.Select(x => (double)x.time);
                        }
                    }

                    // Transform the times in to 'global' space using the clip
                    if (clip != null)
                    {
                        foreach (var k in keys)
                        {
                            var          time = clip.FromLocalTimeUnbound(k);
                            const double eps  = 1e-5;
                            if (time >= clip.start - eps && time <= clip.end + eps)
                            {
                                keyTimes.Add(time);
                            }
                        }
                    }
                    // infinite clip mode, global == local space
                    else
                    {
                        keyTimes.UnionWith(keys);
                    }
                }
            }

            return(keyTimes);
        }
Exemple #6
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();
        }