Example #1
0
        /// <summary> Plays the currently active animation </summary>
        /// <param name="button"> The button reference </param>
        /// <param name="withSound"> If set to <c>true</c> [with sound] </param>
        /// <param name="onStartCallback"> Callback fired when the animation starts playing </param>
        /// <param name="onCompleteCallback"> Callback fired when the animation completed playing </param>
        public void PlayAnimation(UIButton button, bool withSound = true, UnityAction onStartCallback = null, UnityAction onCompleteCallback = null)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (ButtonAnimationType)
            {
            case ButtonAnimationType.Punch:
                if (PunchAnimation == null)
                {
                    return;
                }
                UIAnimator.StopAnimations(button.RectTransform, AnimationType.Punch);
                if (PunchAnimation.Move.Enabled)
                {
                    button.ResetPosition();
                }
                if (PunchAnimation.Rotate.Enabled)
                {
                    button.ResetRotation();
                }
                if (PunchAnimation.Scale.Enabled)
                {
                    button.ResetScale();
                }
                UIAnimator.MovePunch(button.RectTransform, PunchAnimation, button.StartPosition);       //play the move punch animation
                UIAnimator.RotatePunch(button.RectTransform, PunchAnimation, button.StartRotation);     //play the rotate punch animation
                UIAnimator.ScalePunch(button.RectTransform, PunchAnimation, button.StartScale);         //play the scale punch animation
                Coroutiner.Start(InvokeCallbacks(PunchAnimation, onStartCallback, onCompleteCallback));
                break;

            case ButtonAnimationType.State:
                if (StateAnimation == null)
                {
                    return;
                }
                UIAnimator.StopAnimations(button.RectTransform, AnimationType.State);
                UIAnimator.MoveState(button.RectTransform, StateAnimation, button.StartPosition);
                UIAnimator.RotateState(button.RectTransform, StateAnimation, button.StartRotation);
                UIAnimator.ScaleState(button.RectTransform, StateAnimation, button.StartScale);
                UIAnimator.FadeState(button.RectTransform, StateAnimation, button.StartAlpha);
                Coroutiner.Start(InvokeCallbacks(StateAnimation, onStartCallback, onCompleteCallback));
                break;

            case ButtonAnimationType.Animator:
                if (Animators == null || Animators.Count == 0)
                {
                    return;
                }
                foreach (AnimatorEvent animatorEvent in Animators)
                {
                    animatorEvent.Invoke();
                }
                break;
            }

            if (withSound)
            {
                OnTrigger.PlaySound();
            }
        }
Example #2
0
    public void PlayAnimation(BBUIButton _bBButton, UnityEvent onStartCallback = null, UnityEvent onCompleteCallback = null)
    {
        bBButton = _bBButton;
        switch (ButtonAnimationType)
        {
        case ButtonAnimationType.Punch:
            PunchAnimation = uiAnimationData.Animation.Copy();
            if (PunchAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.Punch);
            if (PunchAnimation.Move.Enabled)
            {
                bBButton.ResetPosition();
            }
            if (PunchAnimation.Rotate.Enabled)
            {
                bBButton.ResetRotation();
            }
            if (PunchAnimation.Scale.Enabled)
            {
                bBButton.ResetScale();
            }
            UIAnimator.MovePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartPosition);
            UIAnimator.RotatePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartRotation);
            UIAnimator.ScalePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartScale);
            Coroutiner.Start(InvokeCallbacks(PunchAnimation, onStartCallback, onCompleteCallback));
            break;

        case ButtonAnimationType.State:
            StateAnimation = uiAnimationData.Animation.Copy();
            if (StateAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.State);
            UIAnimator.MoveState(bBButton.RectTransform, StateAnimation, bBButton.StartPosition);
            UIAnimator.RotateState(bBButton.RectTransform, StateAnimation, bBButton.StartRotation);
            UIAnimator.ScaleState(bBButton.RectTransform, StateAnimation, bBButton.StartScale);
            UIAnimator.FadeState(bBButton.RectTransform, StateAnimation, bBButton.StartAlpha);
            Coroutiner.Start(InvokeCallbacks(StateAnimation, onStartCallback, onCompleteCallback));
            break;
        }
    }
Example #3
0
    public void PlayAnimation(BBUIButton _bBButton)
    {
        bBButton = _bBButton;
        switch (ButtonAnimationType)
        {
        case ButtonAnimationType.Punch:
            PunchAnimation = uiAnimationData.Animation.Copy();
            if (PunchAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.Punch);
            if (PunchAnimation.Move.Enabled)
            {
                bBButton.ResetPosition();
            }
            if (PunchAnimation.Rotate.Enabled)
            {
                bBButton.ResetRotation();
            }
            if (PunchAnimation.Scale.Enabled)
            {
                bBButton.ResetScale();
            }
            UIAnimator.MovePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartPosition);
            UIAnimator.RotatePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartRotation);
            UIAnimator.ScalePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartScale);
            break;

        case ButtonAnimationType.State:
            StateAnimation = uiAnimationData.Animation.Copy();
            if (StateAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.State);
            UIAnimator.MoveState(bBButton.RectTransform, StateAnimation, bBButton.StartPosition);
            UIAnimator.RotateState(bBButton.RectTransform, StateAnimation, bBButton.StartRotation);
            UIAnimator.ScaleState(bBButton.RectTransform, StateAnimation, bBButton.StartScale);
            UIAnimator.FadeState(bBButton.RectTransform, StateAnimation, bBButton.StartAlpha);
            break;
        }
    }