示例#1
0
        private static void OnAnimationCompleted(object sender, EventArgs e)
        {
            var component = sender as AnimationCameraComponent;

            component.AnimationCompleted -= OnAnimationCompleted;
            AnimationCompleted?.Invoke(sender, e);
        }
        private static void AnimatorAnimationCompleted(object sender, AnimationCompletedEventArgs e)
        {
#if WPF
            var element = e.Source as Image;
            element?.RaiseEvent(e);
#elif WINRT || SILVERLIGHT
            AnimationCompleted?.Invoke(e.Source, e);
#endif
        }
 private void NotifyPictureForm_FormClosing(object?sender, FormClosingEventArgs e)
 {
     if (!isCompleted && e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel = true;
     }
     else
     {
         AnimationCompleted?.Invoke(this, EventArgs.Empty);
     }
 }
示例#4
0
                private void Da_AnimationCompleted(object sender, ClearUC.Utils.AnimationHelper.AnimationEventArgs e)
                {
                    switch (V)
                    {
                    case Visibility.Hidden:
                        E.Visibility = Visibility.Hidden;
                        break;
                    }

                    AnimationCompleted?.Invoke(this, new EventArgs());
                }
示例#5
0
        public void StartEntranceEffect()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);
            Compositor      compositor = container.Compositor;

            // 设置缩放和动画
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // 创建淡出动画
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Grid的动画
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // 初始屏动画
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // 设置Grid的中心缩放视觉
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(UIToShow);

            gridVisual.Size        = UIToShow.ActualSize;
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;

            // 创建一个视觉组,当改组所有视觉执行完后不再显示
            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += (s, a) =>
            {
                ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                SurfaceLoader.Uninitialize();
                AnimationCompleted?.Invoke(this, null);
            };
            batch.End();
        }
示例#6
0
        public void StartEntranceEffect()
        {
            try
            {
                TimeSpan AnimationDuration = TimeSpan.FromMilliseconds(1000);

                ContainerVisual Container = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);

                ScalarKeyFrameAnimation FadeOutAnimation = Container.Compositor.CreateScalarKeyFrameAnimation();
                FadeOutAnimation.InsertKeyFrame(1, 0);
                FadeOutAnimation.Duration = AnimationDuration;

                Vector2KeyFrameAnimation ScaleUIAnimation = Container.Compositor.CreateVector2KeyFrameAnimation();
                ScaleUIAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
                ScaleUIAnimation.InsertKeyFrame(1, new Vector2(1, 1));
                ScaleUIAnimation.Duration = AnimationDuration;

                Vector2KeyFrameAnimation ScaleSplashAnimation = Container.Compositor.CreateVector2KeyFrameAnimation();
                ScaleSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
                ScaleSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
                ScaleSplashAnimation.Duration = AnimationDuration;

                Visual UIVisual = ElementCompositionPreview.GetElementVisual(UIToShow);
                UIVisual.Size        = new Vector2((float)UIToShow.ActualWidth, (float)UIToShow.ActualHeight);
                UIVisual.CenterPoint = new Vector3(UIVisual.Size.X, UIVisual.Size.Y, 0) * 0.5f;


                CompositionScopedBatch BatchAnimation = Container.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

                Container.StartAnimation("Opacity", FadeOutAnimation);
                Container.StartAnimation("Scale.XY", ScaleSplashAnimation);
                UIVisual.StartAnimation("Scale.XY", ScaleUIAnimation);

                BatchAnimation.Completed += (s, a) =>
                {
                    ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                    SurfaceLoader.Uninitialize();
                    AnimationCompleted?.Invoke(this, null);
                };

                BatchAnimation.End();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error in StartEntranceEffect, message:{ex.Message}");
            }
        }
示例#7
0
        internal void Update(float frameTime)
        {
            if (_playingAnimations.Count == 0)
            {
                return;
            }

            // TODO: Get rid of this ToArray() allocation.
            foreach (var(key, playback) in _playingAnimations.ToArray())
            {
                var keep = UpdatePlayback(Owner, playback, frameTime);
                if (!keep)
                {
                    _playingAnimations.Remove(key);
                    AnimationCompleted?.Invoke(key);
                }
            }
        }
示例#8
0
        private void DoAnimation(CancellationToken token)
        {
            TimeSpan durationFromStart;

            while ((durationFromStart = (DateTime.UtcNow - _startTime).Duration()) < TotalDuration)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                Double completedPart = durationFromStart.TotalMilliseconds / TotalDuration.TotalMilliseconds;
                Animatable.SetAnimationValue(From.MovePoint(completedPart * _vector));
                token.WaitHandle.WaitOne(5);
            }
            Animatable.SetAnimationValue(To);
            if (!token.IsCancellationRequested)
            {
                new Task(() => AnimationCompleted?.Invoke()).Start();
            }
            State = EAnimatorState.Stopped;
        }
示例#9
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects, Color color)
        {
            if (Animation == null)
            {
                return;
            }

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.FrameTime)
            {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate.
                if (Animation.IsLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;
                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }


            // Calculate the source rectangle of the current frame.
            //Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Height, Animation.Texture.Height);
            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.Texture.Height);

            // Draw the current frame.
            spriteBatch.Draw(Animation.Texture, position, source, color, 0.0f, Origin, 1.0f, spriteEffects, 0.0f);

            if (!Animation.IsLooping && frameIndex >= Animation.FrameCount - 1)
            {
                if (AnimationCompleted != null)
                {
                    AnimationCompleted.Invoke(this, new EventArgs());
                }
            }
        }
示例#10
0
 public void OnAnimationCompleted(float target)
 {
     AnimationCompleted?.Invoke(target);
 }
示例#11
0
 protected virtual void OnAnimationCompleted()
 {
     AnimationCompleted?.Invoke(this, new AnimationCompletedEventArgs(AnimationSource));
 }
示例#12
0
 protected virtual void OnAnimationCompleted()
 {
     AnimationCompleted?.Invoke(this, EventArgs.Empty);
 }
 private void OnCompleted()
 {
     AnimationCompleted?.Invoke(this, EventArgs.Empty);
 }
        public void MoveTo(Entity destinationEntity)
        {
            var scene = this.Owner.Scene;

            var cameraPoint = FindCameraPosition(this.Owner);

            List <Transform3D> path = calculatePath(this.Owner, cameraPoint, destinationEntity);

            var limitCameraBehavior = Owner.FindComponent <LimitCameraBehavior>();

            limitCameraBehavior.IsActive = false;

            IGameAction action = null;

            if (path.Count() > 1)
            {
                // rotation action
                IGameAction rotationAction = null;
                for (int i = 0; i < path.Count; i++)
                {
                    if (i == 0)
                    {
                        rotationAction = scene.CreateGameAction(
                            new RotateToShortest3DGameAction(
                                Owner,
                                path[i].Rotation,
                                TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                EaseFunction.None,
                                false,
                                true));
                    }
                    else
                    {
                        rotationAction =
                            rotationAction.ContinueWith(
                                scene.CreateGameAction(
                                    new RotateToShortest3DGameAction(
                                        Owner,
                                        path[i].Rotation,
                                        TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                        (i == path.Count - 1) ? EaseFunction.SineOutEase : EaseFunction.None,
                                        false,
                                        true)));
                    }
                }

                // init movement rotation
                var transform = this.Owner.FindComponent <Transform3D>();
                path.Insert(0, transform);
                CatmullRomSpline catmullRomSpline = new CatmullRomSpline(path.ToArray());

                action = scene.CreateParallelGameActions(
                    new FloatAnimationGameAction(
                        this.Owner,
                        0,
                        1,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase,
                        (lerp) =>
                {
                    transform.Position = catmullRomSpline.GetPosition(lerp);
                }),
                    rotationAction
                    )
                         .WaitAll();
            }
            else
            {
                action = scene.CreateParallelGameActions(
                    new MoveTo3DGameAction(
                        this.Owner,
                        path.Last().Position,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase),
                    new RotateToShortest3DGameAction(
                        this.Owner,
                        path.Last().Rotation,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineOutEase,
                        false,
                        true))
                         .WaitAll();
            }

            if (action != null)
            {
                action.Run();
                action.Completed += (obj) =>
                {
                    limitCameraBehavior.OriginalRotation = path.Last().Rotation;
                    limitCameraBehavior.IsActive         = true;
                    var destinationLimitCameraBehavior = destinationEntity.FindComponent <LimitCameraBehavior>();
                    limitCameraBehavior.MaxPitch = destinationLimitCameraBehavior?.MaxPitch ?? LimitCameraBehavior.DefaultMaxPitch;
                    limitCameraBehavior.MaxYaw   = destinationLimitCameraBehavior?.MaxYaw ?? LimitCameraBehavior.DefaultMaxYaw;

                    // Invoke subscribed
                    AnimationCompleted?.Invoke(this, new EventArgs());
                };
            }
        }
示例#15
0
 protected virtual void OnAnimationCompleted(AnimationEventArgs e)
 {
     AnimationCompleted?.Invoke(this, e);
 }
示例#16
0
 private void Start()
 {
     _queue.QueueEmptied += () => AnimationCompleted?.Invoke();
 }