Example #1
0
        private void Bind(ITimeline timeline, Dictionary <string, INode> nodeDictionary)
        {
            IPropertyTimeline propertyTimeline = timeline as IPropertyTimeline;

            if (propertyTimeline != null && !string.IsNullOrEmpty(propertyTimeline.TargetName))
            {
                INode node;
                nodeDictionary.TryGetValue(propertyTimeline.TargetName, out node);
                propertyTimeline.Target = node;
            }

            ICompositeTimeline compositeTimeline = timeline as ICompositeTimeline;

            if (compositeTimeline != null)
            {
                for (int i = 0; i < compositeTimeline.Children.Count; i++)
                {
                    Bind(compositeTimeline.Children[i], nodeDictionary);
                }
            }
        }
Example #2
0
        public object Load(IContentManager contentManager)
        {
            Type propertyTimelineType = Type.GetType(PropertyTimelineType);

            float inverseDuration = 1.0f / Duration;

            //for (int i = 0; i < _keyFrames.Count; i++)
            //{
            //    _keyFrames[i].Time *= inverseDuration;
            //}

            if (KeyFrames.Count > 1)
            {
                List <SequentialTimeline> timelines = new List <SequentialTimeline>();

                SequentialTimeline sequentialTimeline = new SequentialTimeline();
                sequentialTimeline.BeginTime = 0;
                sequentialTimeline.EndTime   = 1;
                sequentialTimeline.Duration  = 1;

                timelines.Add(sequentialTimeline);

                //masterTimeline.Children.Add(sequentialTimeline);

                IPropertyTimeline previous = null;
                for (int i = 1; i < KeyFrames.Count; i++)
                {
                    //if (_keyFrames[i].FillBehavior == KeyFrameFillBehavior.BeginNewTimeline)
                    //{
                    //    sequentialTimeline.EndTime = KeyFrames[i].Time;


                    //    sequentialTimeline = new SequentialTimeline();
                    //    sequentialTimeline.BeginTime = KeyFrames[i].Time;

                    //    masterTimeline.Children.Add(sequentialTimeline);
                    //}
                    //else
                    //{
                    IPropertyTimeline propertyTimeline = (IPropertyTimeline)Activator.CreateInstance(propertyTimelineType);

                    propertyTimeline.TargetName = TargetName;

                    propertyTimeline.EasingFunction = KeyFrames[i - 1].EasingFunction;
                    propertyTimeline.BeginTime      = KeyFrames[i - 1].Time * inverseDuration;
                    propertyTimeline.EndTime        = 1;
                    propertyTimeline.Duration       = KeyFrames[i].Time * inverseDuration - propertyTimeline.BeginTime;
                    propertyTimeline.FillBehavior   = (FillBehavior)KeyFrames[i].FillBehavior;

                    if (previous != null)
                    {
                        previous.EndTime = propertyTimeline.BeginTime;
                    }

                    propertyTimelineType.GetProperty("From").SetValue(propertyTimeline, KeyFrames[i - 1].Value, null);
                    propertyTimelineType.GetProperty("To").SetValue(propertyTimeline, KeyFrames[i].Value, null);

                    sequentialTimeline.Children.Add(propertyTimeline);
                    //sequentialTimeline.Duration = KeyFrames[i].Time;

                    previous = propertyTimeline;
                    //}
                }

                return(sequentialTimeline);
            }
            else
            {
                IPropertyTimeline propertyTimeline = (IPropertyTimeline)Activator.CreateInstance(propertyTimelineType);
                propertyTimeline.TargetName = TargetName;
                propertyTimeline.BeginTime  = 0;
                propertyTimeline.EndTime    = 1;
                propertyTimeline.Duration   = 1;

                propertyTimeline.EasingFunction = new LinearEase();

                if (KeyFrames.Count > 0)
                {
                    propertyTimelineType.GetProperty("From").SetValue(propertyTimeline, KeyFrames[0].Value, null);
                    propertyTimelineType.GetProperty("To").SetValue(propertyTimeline, KeyFrames[0].Value, null);
                }

                return(propertyTimeline);
            }
        }