/// <summary> /// Used to swap out two groups. One animates in, the other out. /// </summary> /// <param name="oldGroup">The group to animate out</param> /// <param name="newGroup">The group to animate in</param> /// <param name="animOld"></param> /// <param name="animNew"></param> public static void SwapAnimate(CUIGroup oldGroup, CUIGroup newGroup, float overrideTime = -1f, CUIAnimation animOld = CUIAnimation.FadeOut, CUIAnimation animNew = CUIAnimation.FadeIn) { if (oldGroup == newGroup) { return; } I.AnimateInternal(oldGroup, animOld, overrideTime); I.AnimateInternal(newGroup, animNew, overrideTime); }
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)); }
public static void Animate(CUIGroup view, CUIAnimation anim, float overrideTime = -1f) { I.AnimateInternal(view, anim, overrideTime); }