Esempio n. 1
0
        private void PreparePlay()
        {
            for (int i = 0; i < _elements.Count; ++i)
            {
                EffectElementBase element = _elements[i];

                // Check if we have a start value that needs setting.
                if (element.elementType == ElementType.AnimateBetween)
                {
                    View target = _rootView.FindChildByName(element.target);
                    if (target == null)
                    {
                        Console.WriteLine("Effect: Error: Could not find target: " + element.target);
                    }
                    else
                    {
                        int propertyIndex = target.GetPropertyIndex(element.property);
                        if (propertyIndex == -1)
                        {
                            Console.WriteLine("Effect: Error: Could not find property: " + element.property + " in target " + element.target);
                        }
                        else
                        {
                            PropertyValue propertyValue = PropertyValue.CreateFromObject((element as AnimateBetween).startValue);
                            target.SetProperty(propertyIndex, propertyValue);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Play animations
        /// </summary>
        /// <param name="targetView">target view</param>
        /// <param name="speedFactor">speed factor,default value is 1.0f</param>
        public void Play(View targetView = null, float speedFactor = 1.0f)
        {
            EndAnimations();

            Animation animation = new Animation(); // Uninitialized as created as required during loop.

            if (_useAnimation == null)
            {
                _animations.Clear();
            }
            else
            {
                animation             = _animations[0];
                animation.SpeedFactor = speedFactor;
            }

            PreparePlay();

            // We initialise this true to force an animation to be created on the first loop.
            bool lastElementLoopState = true;

            View target = targetView;

            // Add all the animations within the effect-elements to the final animation.
            for (int i = 0; i < _elements.Count; ++i)
            {
                EffectElementBase element = _elements[i];
                int useEndTime            = element.endTime == -1 ? _duration : element.endTime;

                if (targetView == null)
                {
                    target = _rootView.FindChildByName(element.target);
                }

                if (target == null)
                {
                    continue;
                }

                // We want to know if we are going from looping to non-looping, or vice-versa. This is so we know when to create a new animation.
                // It is important that we also do this if we stay as looping, so the only valid state to NOT create an animation is neither old or new are looping.
                // We also check if the current animation has been populated, as if it is empty it can be used anyway.
                // If we are using a user provide animation, we skip this.
                if ((element.looping || lastElementLoopState) && (_useAnimation == null))
                {
                    _animations.Add(new Animation());
                    animation             = _animations[_animations.Count - 1];
                    animation.Duration    = _duration; //TODO: Remove the need for this ? Or keep it if start and end times become percentage fractions.
                    animation.Looping     = element.looping;
                    animation.EndAction   = _endAction;
                    animation.SpeedFactor = speedFactor;
                }

                lastElementLoopState = element.looping;

                // Add an animator to the current animation.
                switch (element.elementType)
                {
                case Effect.ElementType.AnimateTo:
                case Effect.ElementType.AnimateBetween:
                {
                    animation.AnimateTo(target, element.property, element.targetValue, element.startTime, useEndTime, element.alphaFunction);
                    break;
                }

                case Effect.ElementType.AnimateBy:
                {
                    animation.AnimateBy(target, element.property, element.targetValue, element.startTime, useEndTime, element.alphaFunction);
                    break;
                }

                case Effect.ElementType.AnimateKeyframes:
                {
                    AnimateKeyframes animateKeyframes = element as AnimateKeyframes;
                    animation.AnimateBetween(target, element.property, animateKeyframes.keyframes, element.startTime, useEndTime, animateKeyframes.interpolation, element.alphaFunction);
                    break;
                }

                case Effect.ElementType.AnimatePath:
                {
                    AnimatePath animatePath = element as AnimatePath;
                    animation.AnimatePath(target, animatePath.path, element.targetValue as Vector3, element.startTime, useEndTime, element.alphaFunction);
                    break;
                }
                }
            }

            // Loop through the created animations and play them.
            _animatorsRunning = _animations.Count;
            for (int i = 0; i < _animatorsRunning; ++i)
            {
                // Play the current animation
                _animations[i].Finished += AnimatorFinishedHandler;
                _animations[i].Play();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Add element to list
 /// </summary>
 /// <param name="element">effect element</param>
 public void AddAction(EffectElementBase element)
 {
     _elements.Add(element);
 }