Пример #1
0
        /// <summary>
        /// Parse all the keyframe channels data.
        /// </summary>
        private static Keyframes ParseKeyframes(dynamic kkff)
        {
            Keyframes keyframes = new Keyframes();

            if (kkff == null)
            {
                return(keyframes);
            }

            if (kkff.Visibility != null)
            {
                keyframes.Visibility.Clear();
                foreach (var kf in kkff.Visibility)
                {
                    Keyframe <bool> keyframe = new Keyframe <bool>();
                    keyframe.Time          = kf.Time;
                    keyframe.Value         = kf.Value;
                    keyframe.Interpolation = ParseEnum <Interpolation>(kf.Interpolation);
                    keyframes.Visibility.Add(keyframe);
                }
            }

            if (kkff.Offset != null)
            {
                keyframes.Offset.Clear();
                foreach (var kf in kkff.Offset)
                {
                    Keyframe <int> keyframe = new Keyframe <int>();
                    keyframe.Time          = kf.Time;
                    keyframe.Value         = kf.Value;
                    keyframe.Interpolation = ParseEnum <Interpolation>(kf.Interpolation);
                    keyframes.Offset.Add(keyframe);
                }
            }

            if (kkff.Opacity != null)
            {
                keyframes.Opacity.Clear();
                foreach (var kf in kkff.Opacity)
                {
                    Keyframe <float> keyframe = new Keyframe <float>();
                    keyframe.Time          = kf.Time;
                    keyframe.Value         = kf.Value;
                    keyframe.Interpolation = ParseEnum <Interpolation>(kf.Interpolation);
                    keyframes.Opacity.Add(keyframe);
                }
            }

            if (kkff.Transform != null)
            {
                keyframes.Transform.Clear();
                foreach (var kf in kkff.Transform)
                {
                    Keyframe <Transform> keyframe = new Keyframe <Transform>();
                    keyframe.Time          = kf.Time;
                    keyframe.Value         = ParseTransform(kf.Value);
                    keyframe.Interpolation = ParseEnum <Interpolation>(kf.Interpolation);
                    keyframes.Transform.Add(keyframe);
                }
            }

            return(keyframes);
        }
Пример #2
0
        private static JObject WriteKeyframes(Keyframes value)
        {
            JObject jKeyframes = new JObject();

            // Visibility.
            JArray jVisibility = new JArray();

            foreach (var kf in value.Visibility)
            {
                JObject jK = new JObject();
                jK.Add(new JProperty("Time", kf.Time));
                jK.Add(new JProperty("Value", kf.Value));
                jK.Add(new JProperty("Interpolation", kf.Interpolation.ToString()));
                jVisibility.Add(jK);
            }
            jKeyframes.Add(new JProperty("Visibility", jVisibility));

            // Offset.
            JArray jOffset = new JArray();

            foreach (var kf in value.Offset)
            {
                JObject jK = new JObject();
                jK.Add(new JProperty("Time", kf.Time));
                jK.Add(new JProperty("Value", kf.Value));
                jK.Add(new JProperty("Interpolation", kf.Interpolation.ToString()));
                jOffset.Add(jK);
            }
            jKeyframes.Add(new JProperty("Offset", jOffset));

            // Opacity.
            if (value.Opacity.Count > 0)
            {
                JArray jOpacity = new JArray();
                foreach (var kf in value.Opacity)
                {
                    JObject jK = new JObject();
                    jK.Add(new JProperty("Time", kf.Time));
                    jK.Add(new JProperty("Value", kf.Value));
                    jK.Add(new JProperty("Interpolation", kf.Interpolation.ToString()));
                    jOpacity.Add(jK);
                }
                jKeyframes.Add(new JProperty("Opacity", jOpacity));
            }

            // Transform.
            if (value.Transform.Count > 0)
            {
                JArray jTransform = new JArray();
                foreach (var kf in value.Transform)
                {
                    JObject jK = new JObject();
                    jK.Add(new JProperty("Time", kf.Time));
                    jK.Add(new JProperty("Value", WriteTransform(kf.Value)));
                    jK.Add(new JProperty("Interpolation", kf.Interpolation.ToString()));
                    jTransform.Add(jK);
                }
                jKeyframes.Add(new JProperty("Transform", jTransform));
            }

            return(jKeyframes);
        }