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)); }