private IEnumerator AnimateCoin(RectTransform fromRect, float startDelay, float explodeForce) { yield return(new WaitForSeconds(startDelay)); RectTransform coinToAnimate = coinPool.GetObject <RectTransform>(animationContainer); UIAnimation.DestroyAllAnimations(coinToAnimate.gameObject); coinToAnimate.anchoredPosition = SwitchToRectTransform(fromRect, animationContainer); coinToAnimate.sizeDelta = fromRect.sizeDelta; yield return(ExplodeCoinOut(coinToAnimate, explodeForce)); Vector2 toPosition = SwitchToRectTransform(animateToMarker, animationContainer); float duration = animationDuration + Random.Range(-0.1f, 0.1f); PlayAnimation(UIAnimation.PositionX(coinToAnimate, toPosition.x, duration)); PlayAnimation(UIAnimation.PositionY(coinToAnimate, toPosition.y, duration)); PlayAnimation(UIAnimation.Width(coinToAnimate, animateToMarker.sizeDelta.x, duration)); PlayAnimation(UIAnimation.Height(coinToAnimate, animateToMarker.sizeDelta.y, duration)); //播放金币到达目的地音效 //SoundManager.Instance.Play("coin", false, duration - 0.1f); yield return(new WaitForSeconds(duration)); IncCoinTextForAnimation(); }
private void AnimateCoin(RectTransform coinRectTransform, float startDelay, int setCoinAmountTextTo) { RectTransform coinToAnimate = coinPool.GetObject <RectTransform>(); UIAnimation.DestroyAllAnimations(coinToAnimate.gameObject); // 需要将coinToAnimate的比例设置为与coinRectTransform相同的比例 coinToAnimate.SetParent(coinRectTransform.parent, false); coinToAnimate.sizeDelta = coinRectTransform.sizeDelta; coinToAnimate.localScale = coinRectTransform.localScale; coinToAnimate.anchoredPosition = coinRectTransform.anchoredPosition; coinToAnimate.SetParent(animationContainer); Vector2 animateToPosition = SwitchToRectTransform(animateTo, animationContainer); // 指定硬币的x位置上的动画 PlayAnimation(UIAnimation.PositionX(coinToAnimate, animateToPosition.x, animationDuration), startDelay); // 指定硬币的y位置上的动画 PlayAnimation(UIAnimation.PositionY(coinToAnimate, animateToPosition.y, animationDuration), startDelay); // 指定硬币的x缩放上的动画 PlayAnimation(UIAnimation.ScaleX(coinToAnimate, 1, animationDuration), startDelay); // 指定硬币的y缩放上的动画 PlayAnimation(UIAnimation.ScaleY(coinToAnimate, 1, animationDuration), startDelay); // 指定硬币宽度上的动画 PlayAnimation(UIAnimation.Width(coinToAnimate, animateTo.sizeDelta.x, animationDuration), startDelay); // 指定硬币长度上的动画 PlayAnimation(UIAnimation.Height(coinToAnimate, animateTo.sizeDelta.y, animationDuration), startDelay); StartCoroutine(WaitThenSetCoinsText(setCoinAmountTextTo, animationDuration + startDelay)); }
/// <summary> /// Starts the swipe screen transition animation /// </summary> private void StartSwipeAnimation(TransitionInfo transitionInfo, bool show, bool back, float duration) { float screenWidth = RectT.rect.width; float fromX = 0f; float toX = 0f; if (show && back) { fromX = -screenWidth; toX = 0; } else if (show && !back) { fromX = screenWidth; toX = 0; } else if (!show && back) { fromX = 0; toX = screenWidth; } else if (!show && !back) { fromX = 0; toX = -screenWidth; } UIAnimation anim = UIAnimation.PositionX(RectT, fromX, toX, duration); anim.style = transitionInfo.animationStyle; anim.animationCurve = transitionInfo.animationCurve; anim.startOnFirstFrame = true; if (!show) { anim.OnAnimationFinished = (GameObject obj) => { SetVisibility(false); }; } else { anim.OnAnimationFinished = null; } anim.Play(); }
private IEnumerator StartShake(float origX, int shakeAmount, float shakeForce, float shakeAnimDuration) { for (int i = 0; i < shakeAmount; i++) { if (i % 2 == 0) { ShakeLeft(origX, shakeAnimDuration, shakeForce); } else { ShakeRight(origX, shakeAnimDuration, shakeForce); } yield return(new WaitForSeconds(shakeAnimDuration)); } // Move it back to the middle UIAnimation.PositionX(transform as RectTransform, origX, shakeAnimDuration).Play(); shakeRoutine = null; }
private IEnumerator ExplodeCoinOut(RectTransform coinToAnimate, float explodeForce) { Vector2 randDir = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; Vector2 toPosition = coinToAnimate.anchoredPosition + randDir * (explodeForce + Random.Range(0, explodeForceOffset)); UIAnimation anim; anim = UIAnimation.PositionX(coinToAnimate, toPosition.x, explodeAnimationDuration + Random.Range(-0.05f, 0.05f)); anim.style = UIAnimation.Style.EaseOut; anim.Play(); anim = UIAnimation.PositionY(coinToAnimate, toPosition.y, explodeAnimationDuration + Random.Range(-0.05f, 0.05f)); anim.style = UIAnimation.Style.EaseOut; anim.Play(); while (anim.IsPlaying) { yield return(null); } }
private void ShakeRight(float origX, float animDuration, float shakeForce) { UIAnimation.PositionX(transform as RectTransform, origX + shakeForce, animDuration).Play(); }