Example #1
0
        private static AnimationCurve ExtractNormalizedTimeCurve(SceneCachePlayer scPlayer, out float duration)
        {
            ISceneCacheInfo sceneCacheInfo = scPlayer.ExtractSceneCacheInfo(forceOpen: true);

            if (null == sceneCacheInfo)
            {
                duration = 0;
                return(null);
            }

            TimeRange timeRange = sceneCacheInfo.GetTimeRange();

            duration = timeRange.GetDuration();
            if (duration <= 0f)
            {
                duration = Mathf.Epsilon;
            }

            Keyframe[] keyframes    = sceneCacheInfo.GetTimeCurve().keys;
            int        numKeyframes = keyframes.Length;

            for (int i = 0; i < numKeyframes; ++i)
            {
                keyframes[i].value /= timeRange.end;
            }

            //outTangent
            for (int i = 0; i < numKeyframes - 1; ++i)
            {
                keyframes[i].outTangent = CalculateLinearTangent(keyframes, i, i + 1);
            }

            //inTangent
            for (int i = 1; i < numKeyframes; ++i)
            {
                keyframes[i].inTangent = CalculateLinearTangent(keyframes, i - 1, i);
            }

            AnimationCurve curve = new AnimationCurve(keyframes);

            return(curve);
        }