public void Read(FileStream fs) { this.header = (UIMotionData.Property.PropertyHeader)UIMotionData.ReadObject(fs, typeof(UIMotionData.Property.PropertyHeader)); int num = 0; while ((long)num < (long)((ulong)this.header.keyframeNum)) { UIMotionData.Property.Keyframe keyframe = (UIMotionData.Property.Keyframe)UIMotionData.ReadObject(fs, typeof(UIMotionData.Property.Keyframe)); this.keyframes.Add(keyframe); num++; } }
private void SetMotionData(UIMotionData data) { float timeScale = data.header.timeScale; Func <float, float> func = (float timeValue) => timeValue / timeScale * 1000f; this.duration = func.Invoke(data.header.duration); using (List <UIMotionData.Property> .Enumerator enumerator = data.properties.GetEnumerator()) { while (enumerator.MoveNext()) { UIMotionData.Property current = enumerator.Current; AnimationInterpolator easingCurve; if (current.header.useTimeMap) { int strength = data.timeMaps[(int)current.header.timeMapIndex].header.strength; switch (data.timeMaps[(int)current.header.timeMapIndex].header.easeType) { case EaseType.Quadratic: easingCurve = AnimationUtility.GetQuadInterpolator(strength); break; case EaseType.Cubic: easingCurve = AnimationUtility.GetCubicInterpolator(strength); break; case EaseType.Quartic: easingCurve = AnimationUtility.GetQuarticInterpolator(strength); break; case EaseType.Quintic: easingCurve = AnimationUtility.GetQuinticInterpolator(strength); break; case EaseType.DualQuadratic: easingCurve = AnimationUtility.GetDualQuadInterpolator(strength); break; case EaseType.DualCubic: easingCurve = AnimationUtility.GetDualCubicInterpolator(strength); break; case EaseType.DualQuartic: easingCurve = AnimationUtility.GetDualQuarticInterpolator(strength); break; case EaseType.DualQuintic: easingCurve = AnimationUtility.GetDualQuinticInterpolator(strength); break; case EaseType.Bounce: easingCurve = AnimationUtility.GetBounceInterpolator(strength); break; case EaseType.BounceIn: easingCurve = AnimationUtility.GetBounceInInterpolator(strength); break; case EaseType.Spring: easingCurve = AnimationUtility.GetSpringInterpolator(strength); break; case EaseType.SineWave: easingCurve = AnimationUtility.GetSineWaveInterpolator(strength); break; case EaseType.SawtoothWave: easingCurve = AnimationUtility.GetSawtoothWaveInterpolator(strength); break; case EaseType.SquareWave: easingCurve = AnimationUtility.GetSquareWaveInterpolator(strength); break; case EaseType.RandomSquareWave: easingCurve = AnimationUtility.GetRandomSquareWaveInterpolator(strength); break; case EaseType.DampedWave: easingCurve = AnimationUtility.GetDampedWaveInterpolator(strength); break; default: easingCurve = new AnimationInterpolator(AnimationUtility.LinearInterpolator); break; } } else { easingCurve = new AnimationInterpolator(AnimationUtility.LinearInterpolator); } if (current.keyframes.Count > 0) { UIMotionData.Property.Keyframe keyframe = current.keyframes[0]; AnimationUtility.CubicBezierCurveSequence cubicBezierCurveSequence = new AnimationUtility.CubicBezierCurveSequence(func.Invoke(keyframe.time), keyframe.anchorY); cubicBezierCurveSequence.EasingCurve = easingCurve; for (int i = 0; i < current.keyframes.Count - 1; i++) { int num = i; int num2 = i + 1; UIMotionData.Property.Keyframe keyframe2 = current.keyframes[num]; UIMotionData.Property.Keyframe keyframe3 = current.keyframes[num2]; float num3 = keyframe2.time; float num4 = keyframe3.time; float control1X = func.Invoke(keyframe2.nextX + num3); float control1Y = keyframe2.nextY; float control2X = func.Invoke(keyframe3.previousX + num4); float control2Y = keyframe3.previousY; float nextAnchorX = func.Invoke(keyframe3.time); float nextAnchorY = keyframe3.anchorY; cubicBezierCurveSequence.AppendSegment(control1X, control1Y, control2X, control2Y, nextAnchorX, nextAnchorY); } this.timelines.Add(current.header.propertyType, cubicBezierCurveSequence); } } } }