コード例 #1
0
        private static IEnumerator HandleAnimationData(CUIAnimationState state)
        {
            if (state.tweens.Count <= 0 && !state.isInstant)
            {
                yield break;
            }

            //Add the new data to the list
            currentAnimations.Add(state);

            //Trigger events:
            if (state.isChangingVisibility)
            {
                if (state.isShowing)
                {
                    state.cuiGroup.OnShowing();
                }
                else
                {
                    state.cuiGroup.OnHiding();
                }
            }

            //Wait for the animation to complete
            if (!state.isInstant)
            {
                //Preview for in-editor
                if (!Application.isPlaying)
                {
                    CUITweenPreview.PrepareTweens(state.tweens);
                    CUITweenPreview.StartTweens();
                }

                yield return(new WaitForSeconds(state.animLength));

                while (state.tweens[0].active)
                {
                    yield return(null);
                }
            }

            //Check if it's still valid, if so remove it
            if (currentAnimations.Contains(state))
            {
                //Move the rect to it's final pos after the animation is done
                state.cuiGroup.rectTransform.localPosition = state.finalPos;

                //Disable the GO if needed
                if (!state.isShowing && state.cuiGroup.disableCanvasWhenHidden)
                {
                    state.cuiGroup.gameObject.SetActive(false);
                }

                currentAnimations.Remove(state);
            }
        }
コード例 #2
0
        private static void KillActiveAnimations(CUIGroup cuiGroup)
        {
            //Kill any existing animations
            CUIAnimationState existingState = currentAnimations.Find(x => x.cuiGroup == cuiGroup);

            if (existingState != null)
            {
                currentAnimations.Remove(existingState);

                foreach (Tween tween in existingState.tweens)
                {
                    tween?.Kill();
                }

                //Set the group to whatever final pos it had
                existingState.cuiGroup.rectTransform.localPosition = existingState.finalPos;
            }
        }
コード例 #3
0
        private void AnimateInternal(CUIGroup cuiGroup, CUIAnimation anim, float overrideTime = -1f)
        {
            KillActiveAnimations(cuiGroup);


            float animTime = defaultAnimTime;

            if (overrideTime > 0f)
            {
                animTime = overrideTime;
            }


            CUIAnimationState state = new CUIAnimationState {
                cuiGroup = cuiGroup,
                finalPos = cuiGroup.rectTransform.localPosition
            };

            Vector3 curPos = cuiGroup.rectTransform.localPosition;

            Vector3 posAmt   = Vector3.zero;
            Vector3 scaleAmt = Vector3.one;

            Rect rect = cuiGroup.rectTransform.rect;

            switch (anim)
            {
            case CUIAnimation.FadeIn:
                state.isShowing = true;
                break;

            case CUIAnimation.FadeOut:
                state.isShowing = false;
                break;

            case CUIAnimation.InstantIn:
                state.isShowing = true;
                state.isInstant = true;
                break;

            case CUIAnimation.InstantOut:
                state.isShowing = false;
                state.isInstant = true;
                break;


            case CUIAnimation.FadeInDown:
                posAmt          = new Vector3(0f, rect.height, 0f);
                state.isShowing = true;
                break;

            case CUIAnimation.FadeOutDown:
                posAmt          = new Vector3(0f, -rect.height, 0f);
                state.isShowing = false;
                break;

            case CUIAnimation.FadeInUp:
                posAmt          = new Vector3(0f, -rect.height, 0f);
                state.isShowing = true;
                break;

            case CUIAnimation.FadeOutUp:
                posAmt          = new Vector3(0f, rect.height, 0f);
                state.isShowing = false;
                break;
            }

            state.animLength = animTime;

            if (state.isShowing)
            {
                state.cuiGroup.gameObject.SetActive(true);
            }


            //POSITION ANIMATION
            if (posAmt != Vector3.zero)
            {
                Tween posTween;

                //If we're showing, posAmt + curPos is the starting position for the animation, and the current pos is the end.
                if (state.isShowing)
                {
                    cuiGroup.rectTransform.localPosition = curPos + posAmt;
                    posTween = cuiGroup.rectTransform.DOLocalMove(curPos, animTime).SetEase(animEasing);
                }
                //Else, posAmt + curPos is the amount we should move when animating
                else
                {
                    posTween = cuiGroup.rectTransform.DOLocalMove(curPos + posAmt, animTime).SetEase(animEasing);
                }

                state.tweens.Add(posTween);
            }

            //SCALING ANIMATION
            if (scaleAmt != Vector3.one)
            {
                //data.tweeners.Add();
            }

            //FADING ANIMATION
            if (state.isChangingVisibility && state.isShowing)
            {
                if (state.isInstant)
                {
                    state.cuiGroup.canvasGroup.alpha = 1f;
                }
                else
                {
                    state.tweens.Add(state.cuiGroup.canvasGroup.DOFade(1f, state.animLength));
                }
            }
            else if (state.isChangingVisibility)
            {
                if (state.isInstant)
                {
                    state.cuiGroup.canvasGroup.alpha = 0f;
                }
                else
                {
                    state.tweens.Add(state.cuiGroup.canvasGroup.DOFade(0f, state.animLength));
                }
            }


            StartCoroutine(HandleAnimationData(state));
        }