Example #1
0
        /// <summary>
        /// Executes the "out" animation of this animator, if any.
        /// </summary>
        /// <returns>Whether the animation was executed.</returns>
        public override bool AnimateOut()
        {
            if (outAnimation == null)
            {
                Debug.LogWarning("AnimateOut called in an animator with no associated 'out' animation");

                if (pingPongAnimation != null && pingPongAnimation.HasBegan)
                {
                    StopPingPongAnimation();
                }

                return(false);
            }

            if (outAnimation.IsEnabled && !outAnimation.HasBegan)
            {
                StopPingPongAnimation();

                OutAnimationWillBegin();
                outAnimation.HasBegan    = true;
                outAnimation.IsAnimating = false;
                outAnimation.IsDone      = false;

                ValueToAnimation valueTo = new ValueToAnimation(
                    gameObject,
                    new Action <float>(AnimateOutUpdate),
                    0f,
                    1f,
                    outAnimation.Duration / AnimationManager.Instance.Configuration.AnimationSpeed)
                                           .SetDelay(outAnimation.Delay / AnimationManager.Instance.Configuration.AnimationSpeed)
                                           .SetEaseType(outAnimation.EaseType)
                                           .SetOnComplete(new Action(AnimateOutComplete));

                tween = tweener.StartValueTo(valueTo);

                if (animationObserver != null)
                {
                    animationObserver.OutAnimationStarted(outAnimation);
                }

                if (outAnimation.Sounds.Begin != null)
                {
                    AudioManager.Instance.PlaySoundOneShot(outAnimation.Sounds.Begin);
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Executes the "ping pong" animation of this animator, if any.
        /// </summary>
        /// <returns>Whether the animation was executed.</returns>
        public override bool AnimatePingPong()
        {
            if (pingPongAnimation == null)
            {
                Debug.LogWarning("AnimatePingPong called in an animator with no associated 'ping pong' animation");
                return(false);
            }

            if (gameObject != null && gameObject.activeSelf && enabled)
            {
                StopPingPongAnimation();

                pingPongAnimation.HasBegan    = true;
                pingPongAnimation.IsAnimating = false;
                pingPongAnimation.IsDone      = false;
                PingPongAnimationWillBegin();

                ValueToAnimation valueTo = new ValueToAnimation(
                    gameObject,
                    new Action <float>(AnimatePingPongUpdate),
                    0f,
                    1f,
                    pingPongAnimation.Duration / AnimationManager.Instance.Configuration.AnimationSpeed)
                                           .SetDelay(pingPongAnimation.Delay / AnimationManager.Instance.Configuration.AnimationSpeed)
                                           .SetEaseType(pingPongAnimation.EaseType)
                                           .SetPingPongLoop(true)
                                           .SetOnComplete(new Action(AnimatePingPongComplete));

                tween = tweener.StartValueTo(valueTo);

                if (animationObserver != null)
                {
                    animationObserver.PingPongAnimationStarted(pingPongAnimation);
                }

                return(true);
            }

            return(false);
        }