public void Bake_Keyframes_IsAccurateOnBakedKeys()
            {
                var frames = new Keyframe[]
                {
                    new Keyframe(0, 0),
                    new Keyframe(1, 1),
                    new Keyframe(2, 2),
                    new Keyframe(3, 3),
                    new Keyframe(4, 4),
                    new Keyframe(5, 5)
                };

                var newFrames = new Keyframe[6];

                frames.CopyTo(newFrames, 0);

                AnimationCurveBake.Bake(ref newFrames, 30);
                int seekIndex = 0;

                for (int i = 0; i < newFrames.Length; i++)
                {
                    float actual   = KeyframeUtilities.Evaluate(newFrames[i].time, ref i, newFrames);
                    float expected = KeyframeUtilities.Evaluate(newFrames[i].time, ref seekIndex, frames);
                    Assert.AreEqual(expected, actual, 0.000001f);
                }
            }
            public void Bake_Keyframes_IsAccurateInBetweenKeys()
            {
                var frames = new Keyframe[]
                {
                    new Keyframe(0, 0),
                    new Keyframe(1, 1),
                    new Keyframe(2, 2),
                    new Keyframe(3, 3),
                    new Keyframe(4, 4),
                    new Keyframe(5, 5)
                };

                var newFrames = new Keyframe[6];

                frames.CopyTo(newFrames, 0);

                AnimationCurveBake.Bake(ref newFrames, 30);
                int index1 = 0;
                int index2 = 0;

                float deltaTime = 5 / 900;

                for (int i = 0; i < 900; i++)
                {
                    float actual   = KeyframeUtilities.Evaluate(i * deltaTime, ref index1, newFrames);
                    float expected = KeyframeUtilities.Evaluate(i * deltaTime, ref index2, frames);
                    Assert.AreEqual(expected, actual);
                }
            }
예제 #3
0
        private static AnimationCurve CreateInOutCurve(Keyframe[] inKeyframes)
        {
            var outKeyframes = new Keyframe[inKeyframes.Length];

            inKeyframes.CopyTo(outKeyframes, 0);
            RotateKeyframes(outKeyframes);
            var inOutKeyframes = new Keyframe[inKeyframes.Length * 2];

            MoveAndScaleKeyframes(inKeyframes, Vector2.zero, .5f);
            MoveAndScaleKeyframes(outKeyframes, Vector2.one * .5f, .5f);
            inKeyframes.CopyTo(inOutKeyframes, 0);
            outKeyframes.CopyTo(inOutKeyframes, inKeyframes.Length);
            return(new AnimationCurve(inOutKeyframes));
        }