Esempio n. 1
0
        /// <summary>
        /// Executes the "out" animation in the given context.
        /// </summary>
        /// <param name="context">The context of the animation.</param>
        /// <returns>Whether the animation was executed.</returns>
        public bool AnimateOut(AnimationContext context)
        {
            bool animated = false;

            if (!CanRunAnimation(context))
            {
                return(false);
            }

            switch (context)
            {
            case AnimationContext.Self:
                animated |= AnimateOut();
                break;

            case AnimationContext.SelfAndChildren:
                animated |= AnimateOut();
                animated |= AnimateOutChildren();
                break;

            case AnimationContext.Children:
                animated |= AnimateOutChildren();
                break;
            }

            return(animated);
        }
Esempio n. 2
0
        internal static AnimationContext Animate(this FrameworkElement target)
        {
            var result = new AnimationContext();

            result.Targets.Add(target);
            return(result);
        }
        protected override void StartShowAnimation(UIElement element, AnimationContext context)
        {
            var visual     = ElementCompositionPreview.GetElementVisual(element);
            var compositor = visual.Compositor;

            var fadeInAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeInAnimation.InsertKeyFrame(0.0f, 0.0f);

            if (HasBoundsChangeAnimationsPending && HasHideAnimationsPending)
            {
                fadeInAnimation.InsertKeyFrame(0.66f, 0.0f);
            }
            else if (HasBoundsChangeAnimationsPending || HasHideAnimationsPending)
            {
                fadeInAnimation.InsertKeyFrame(0.5f, 0.0f);
            }

            fadeInAnimation.InsertKeyFrame(1.0f, 1.0f);
            fadeInAnimation.Duration = TimeSpan.FromMilliseconds(
                DefaultAnimationDurationInMs * ((HasHideAnimationsPending ? 1 : 0) + (HasBoundsChangeAnimationsPending ? 1 : 0) + 1) * AnimationSlowdownFactor);

            var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            visual.StartAnimation("Opacity", fadeInAnimation);
            batch.End();
            batch.Completed += delegate { OnShowAnimationCompleted(element); };
        }
Esempio n. 4
0
        private static void InstallAnimations(RectTransformElement rte, GameObject gameObject, IReadOnlyLayoutContext context)
        {
            AnimationContext animationContext = new AnimationContext();

            List <(UIAnimation, AnimationElement)> listOfAnimations = new List <(UIAnimation, AnimationElement)>();

            foreach (var anim in rte.Animations)
            {
                var         constructor = Constructors.GetAnimationConstructor(anim);
                UIAnimation animation   = constructor.Install(gameObject, anim, context);

                if (!string.IsNullOrEmpty(anim.Key))
                {
                    animationContext.AddAnimation(context.ParseString(anim.Key), animation);
                }

                listOfAnimations.Add((animation, anim));
            }

            foreach (var pair in listOfAnimations)
            {
                var anim      = pair.Item2;
                var animation = pair.Item1;
                foreach (var trigger in anim.Triggers)
                {
                    var       constructor      = Constructors.GetTriggerConstructor(trigger);
                    UITrigger triggerComponent = constructor.Install(gameObject, trigger, context, animationContext);

                    triggerComponent.conditions = ParseConditions(trigger.Conditions, gameObject, context);
                    triggerComponent.instant    = context.ParseBool(trigger.Instant);
                    triggerComponent.animation  = animation;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Checks whether an animation can start now.
        /// </summary>
        /// <param name="context">The AnimationContext of the animation.</param>
        /// <returns>A boolean indicating if an animation can start now.</returns>
        protected bool CanRunAnimation(AnimationContext context)
        {
            bool isValid = true;

            if (IsAnimating(context))
            {
                AnimatorConfiguration          configuration         = AnimationManager.Instance.Configuration;
                AnimationInterruptionBehaviour interruptionbehaviour = configuration.InterruptionBehavior;

                switch (interruptionbehaviour)
                {
                case AnimationInterruptionBehaviour.LetItFinish:
                    Debug.LogWarning("Animation not executed because another animation is already running");
                    isValid = false;
                    break;

                case AnimationInterruptionBehaviour.Interrupt:
                    Debug.LogWarning("Interrupting currently running animation, so another one can start");
                    StopAnimation(context);
                    StopPingPongAnimation(context);
                    isValid = true;
                    break;
                }
            }

            return(isValid);
        }
Esempio n. 6
0
        private static AnimationContext SingleProperty(this AnimationContext target, string propertyPath, params double[] args)
        {
            var values = args.ToList();

            if (args.Length % 2 != 0)
            {
                throw new InvalidOperationException("Params should come in a time-value pair");
            }

            foreach (var element in target.Targets)
            {
                var moveX = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(moveX, element);
                Storyboard.SetTargetProperty(moveX, new PropertyPath(propertyPath));

                for (int i = 0; i < values.Count; i += 2)
                {
                    moveX.KeyFrames.Add(new SplineDoubleKeyFrame()
                    {
                        KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(values[i])),
                        Value   = values[i + 1]
                    });
                }

                target.Instance.Children.Add(moveX);
            }

            target.StartIndex = target.EndIndex;
            target.EndIndex  += target.Targets.Count;

            return(target);
        }
Esempio n. 7
0
 /// <summary>
 ///		Makes sure that the animated object has the needed opacity mask.
 /// </summary>
 /// <remarks>
 ///		<para>
 ///			Adds a vertical or horizontal opacity mask of the kind:
 ///		</para>
 ///		<![CDATA[
 ///		<LinearGradientBrush EndPoint="0 1">
 ///		    <LinearGradientBrush.RelativeTransform>
 ///		        <TranslateTransform Y="0" />
 ///		    </LinearGradientBrush.RelativeTransform>
 ///		    <GradientStop Offset="0" Color="Transparent" />
 ///		    <GradientStop Offset="0" Color="Black" />
 ///		    <GradientStop Offset="1" Color="Black" />
 ///		    <GradientStop Offset="1" Color="Transparent" />
 ///		</LinearGradientBrush>
 ///		]]>
 ///		</remarks>
 /// <param name="target">The object to set the mask for.</param>
 internal static AnimationContext EnsureOpacityMask(this AnimationContext target)
 {
     foreach (var element in target.Targets)
     {
         var mask = new LinearGradientBrush()
         {
             EndPoint = new Point(0, 1)
         };
         mask.GradientStops.Add(new GradientStop()
         {
             Offset = 0, Color = Colors.Transparent
         });
         mask.GradientStops.Add(new GradientStop()
         {
             Offset = 0, Color = Colors.Black
         });
         mask.GradientStops.Add(new GradientStop()
         {
             Offset = 1, Color = Colors.Black
         });
         mask.GradientStops.Add(new GradientStop()
         {
             Offset = 1, Color = Colors.Transparent
         });
         mask.RelativeTransform = new TranslateTransform();
         mask.Transform         = new TranslateTransform();
         element.OpacityMask    = mask;
     }
     return(target);
 }
Esempio n. 8
0
 internal static AnimationContext EnsureOpacityMask(this AnimationContext target)
 {
     foreach (FrameworkElement element in target.Targets)
     {
         element.OpacityMask = new LinearGradientBrush
         {
             EndPoint      = new Point(0.0, 1.0),
             GradientStops =
             {
                 new GradientStop {
                     Offset = 0.0, Color = Colors.Transparent
                 },
                 new GradientStop {
                     Offset = 0.0, Color = Colors.Black
                 },
                 new GradientStop {
                     Offset = 1.0, Color = Colors.Black
                 },
                 new GradientStop {
                     Offset = 1.0, Color = Colors.Transparent
                 }
             },
             RelativeTransform = new TranslateTransform()
         };
     }
     return(target);
 }
 public bool HasBoundsChangeAnimation(
     UIElement element,
     AnimationContext context,
     Rect oldBounds,
     Rect newBounds)
 {
     return(HasBoundsChangeAnimationCore(element, context, oldBounds, newBounds));
 }
Esempio n. 10
0
 protected override void UpdateCore(AnimationContext context)
 {
     if (context.Time / m_diffTicks >= 1)
     {
         context.Time             = 0;
         context.Sprite.Rotation += m_diffRadians;
     }
 }
Esempio n. 11
0
        public static AnimationContext Update(this Storyboard target)
        {
            var result = new AnimationContext();

            result.Instance = target;
            result.IsUpdate = true;
            return(result);
        }
Esempio n. 12
0
 internal static AnimationContext With(this AnimationContext target, params FrameworkElement[] newElements)
 {
     foreach (var elements in newElements)
     {
         target.Targets.Add(elements);
     }
     return(target);
 }
Esempio n. 13
0
 internal static AnimationContext Origin(this AnimationContext target, double x1, double x2)
 {
     foreach (FrameworkElement element in target.Targets)
     {
         element.RenderTransformOrigin = new Point(x1, x2);
     }
     return(target);
 }
Esempio n. 14
0
 internal static AnimationContext PlayIfPossible(this AnimationContext target, Control hostControl)
 {
     if (AnimationManager.IsGlobalAnimationEnabled && AnimationManager.GetIsAnimationEnabled(hostControl))
     {
         target.Instance.Begin();
     }
     return(target);
 }
Esempio n. 15
0
 protected virtual void StartBoundsChangeAnimation(
     UIElement element,
     AnimationContext context,
     Rect oldBounds,
     Rect newBounds)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 internal static AnimationContext Without(this AnimationContext target, params FrameworkElement[] newElements)
 {
     foreach (FrameworkElement element in newElements)
     {
         target.Targets.Remove(element);
     }
     return(target);
 }
 protected override bool HasBoundsChangeAnimationCore(
     UIElement element,
     AnimationContext context,
     Rect oldBounds,
     Rect newBounds)
 {
     return(true);
 }
        /// <summary>
        ///		When overridden in a derived class this method updates the animation
        ///		before it is played.
        /// </summary>
        /// <param name="target">The control for which the animation needs to be updated.</param>
        /// <param name="storyboard">Storyboard that needs to be updated.</param>
        /// <param name="args">A set of arguments used for animation creation.</param>
        /// <remarks>
        ///		<para>
        ///			Currently the method sets the <see cref="SpeedRatio"/> of the storyboard to
        ///			the global <strong>AnimationSpeedRatio</strong> if the local <see cref="SpeedRatio"/> is null.
        ///			If the local <see cref="SpeedRatio"/> value is set, it will be used.
        ///		</para>
        /// </remarks>
        internal void UpdateAnimation(UIElement target, Storyboard storyboard, params object[] args)
        {
            storyboard.BeginTime = this.InitialDelay;
            AnimationContext context = new AnimationContext(target, storyboard, args);

            this.UpdateAnimationOverride(context);
            storyboard.SpeedRatio  = this.GetSpeedRatio();
            storyboard.AutoReverse = this.AutoReverse.GetValueOrDefault();
        }
Esempio n. 19
0
 internal static AnimationContext Animate(this AnimationContext target, params FrameworkElement[] newTargets)
 {
     target.Targets.Clear();
     foreach (FrameworkElement element in newTargets)
     {
         target.Targets.Add(element);
     }
     return(target);
 }
Esempio n. 20
0
        protected override void UpdateCore(AnimationContext context)
        {
            var relativeContext = (RelativeValueAnimationContext)context;

            var newValue = Function.GetValue(relativeContext.Time, relativeContext.StartValue, relativeContext.FinalValue, Duration);

            relativeContext.Sprite.Rotation += newValue - relativeContext.PrevValue;
            relativeContext.PrevValue        = newValue;
        }
Esempio n. 21
0
 internal static AnimationContext Easings(this AnimationContext target, int index, IEasingFunction easing)
 {
     for (var num = target.StartIndex; num < target.EndIndex; num++)
     {
         var animation = target.Instance.Children[num] as DoubleAnimationUsingKeyFrames;
         var keyFrame  = animation.KeyFrames[index] as EasingDoubleKeyFrame;
         keyFrame.EasingFunction = easing;
     }
     return(target);
 }
Esempio n. 22
0
 private void Deinitialize()
 {
     _character?.Release();
     _character = null;
     _actionController?.Release();
     _actionController = null;
     _animationContext?.Release();
     _animationContext = null;
     _dirty            = true;
     _destroyed        = true;
 }
Esempio n. 23
0
 public ElementInfo(
     UIElement element,
     AnimationTrigger trigger,
     AnimationContext context)
 {
     Element   = element;
     Trigger   = trigger;
     Context   = context;
     OldBounds = default;
     NewBounds = default;
 }
Esempio n. 24
0
 public void OnElementHidden(UIElement element, AnimationContext context)
 {
     if (HasHideAnimation(element, (AnimationContext)(context)))
     {
         HasHideAnimationsPending = true;
         SharedContext           |= context;
         QueueElementForAnimation(new ElementInfo(
                                      element,
                                      AnimationTrigger.Hide,
                                      context));
     }
 }
Esempio n. 25
0
        internal static AnimationContext Discrete(
            this AnimationContext target, DependencyProperty propertyPath, params object[] args)
        {
            List <object> list = args.ToList();

            if ((args.Length % 2) != 0)
            {
                throw new InvalidOperationException("Params should come in a time-value pair");
            }
            target.StartIndex = target.EndIndex;
            target.EndIndex  += target.Targets.Count;
            int num = 0;

            foreach (FrameworkElement element in target.Targets)
            {
                if (target.IsUpdate)
                {
                    var frames = target.Instance.Children[target.StartIndex + num] as ObjectAnimationUsingKeyFrames;
                    if (frames != null)
                    {
                        for (int j = 0; j < list.Count; j += 2)
                        {
                            var frame = frames.KeyFrames[j / 2] as DiscreteObjectKeyFrame;
                            if (frame != null)
                            {
                                frame.KeyTime =
                                    KeyTime.FromTimeSpan(
                                        TimeSpan.FromSeconds(Convert.ToDouble(list[j], CultureInfo.InvariantCulture)));
                                frame.Value = list[j + 1];
                            }
                        }
                    }
                    num++;
                    continue;
                }
                var frames2 = new ObjectAnimationUsingKeyFrames();
                Storyboard.SetTarget(frames2, element);
                Storyboard.SetTargetProperty(frames2, new PropertyPath(propertyPath));
                for (int i = 0; i < list.Count; i += 2)
                {
                    frames2.KeyFrames.Add(
                        new DiscreteObjectKeyFrame
                    {
                        KeyTime =
                            KeyTime.FromTimeSpan(
                                TimeSpan.FromSeconds(Convert.ToDouble(list[i], CultureInfo.InvariantCulture))),
                        Value = list[i + 1]
                    });
                }
                target.Instance.Children.Add(frames2);
            }
            return(target);
        }
Esempio n. 26
0
 internal static AnimationContext EaseAll(this AnimationContext target, IEasingFunction easing)
 {
     for (var num = target.StartIndex; num < target.EndIndex; num++)
     {
         var animation = target.Instance.Children[num] as DoubleAnimationUsingKeyFrames;
         foreach (var keyFrame in animation.KeyFrames.Cast <EasingDoubleKeyFrame>())
         {
             keyFrame.EasingFunction = easing;
         }
     }
     return(target);
 }
Esempio n. 27
0
 internal static AnimationContext Splines(this AnimationContext target, int index, double x1, double y1, double x2, double y2)
 {
     for (var num = target.StartIndex; num < target.EndIndex; num++)
     {
         ((target.Instance.Children[num] as DoubleAnimationUsingKeyFrames).KeyFrames[index] as SplineDoubleKeyFrame).KeySpline = new KeySpline()
         {
             ControlPoint1 = new Point(x1, y1),
             ControlPoint2 = new Point(x2, y2)
         };
     }
     return(target);
 }
Esempio n. 28
0
            public ElementInfo(
                UIElement element,
                AnimationTrigger trigger,
                AnimationContext context)
            {
                Debug.Assert(trigger != AnimationTrigger.BoundsChange);

                Element   = element;
                Trigger   = trigger;
                Context   = context;
                OldBounds = default;
                NewBounds = default;
            }
Esempio n. 29
0
        protected override void PostExecute(UITransitionContext context, ref AnimationContext animContext, bool hideSourcePanel)
        {
            RectTransform rc = context.from.rect;

            rc.offsetMin = animContext.rectTo.GetMinExtents();
            rc.offsetMax = animContext.rectTo.GetMaxExtents();

            if (context.from != null && context.from.rect != null)
            {
                context.from.rect.gameObject.SetActive(false);
                context.from.OnUIHide();
            }
        }
Esempio n. 30
0
 public ElementInfo(
     UIElement element,
     AnimationTrigger trigger,
     AnimationContext context,
     Rect oldBounds,
     Rect newBounds)
 {
     Element   = element;
     Trigger   = trigger;
     Context   = context;
     OldBounds = oldBounds;
     NewBounds = newBounds;
 }
		internal static AnimationContext Animate(this FrameworkElement target)
		{
			var result = new AnimationContext();
			result.Targets.Add(target);
			return result;
		}