public void ReShuffle(int[] unShuffleData, Action onFinished) { var shuffleAnimationWaiter = new FinishableGroupWaiter(onFinished); var reShuffledCards = new CardController[unShuffleData.Length]; for (int i = 0, iMax = unShuffleData.Length; i < iMax; ++i) { CardController lastCard = reShuffledCards[i] = _Cards[unShuffleData[i]]; lastCard.ViewFSM.SetTextVisibility(true); AnimateShuffle(lastCard, i); shuffleAnimationWaiter.AddFinishable(lastCard.Holder); } if (_shuffleAnimationCamera != null && _shuffleAnimationOriginPoint != null) { shuffleAnimationWaiter.AddFinishable( _shuffleAnimationCamera.AddPositionPingPongTween(_shuffleAnimationCamera.transform.position + Vector3.up * _CardAnimationData.CameraShuffleTweenUpAmount) .SetDuration(_CardAnimationData.DeckShuffleExplosionDuration)); } _Cards.Clear(); _Cards.AddRange(reShuffledCards); shuffleAnimationWaiter.Ready = true; if (CardFlipAudio != null) { CardFlipAudio.PlayOneShot(_cardShuffleClip); StartCoroutine(PlayCardRuffleClip()); } }
public void Shuffle(out int[] unShuffleData, Action onFinished) { var cardsToShuffleFrom = new List <CardController>(_Cards); var cardsToShuffleTo = new List <CardController>(_Cards.Count); unShuffleData = new int[_Cards.Count]; var shuffleAnimationWaiter = new FinishableGroupWaiter(onFinished); for (int i = 0; cardsToShuffleFrom.Count > 0; ++i) { int index = Mathf.RoundToInt(UnityEngine.Random.value * (cardsToShuffleFrom.Count - 1)); cardsToShuffleTo.Add(cardsToShuffleFrom[index]); cardsToShuffleFrom.RemoveAt(index); unShuffleData[i] = _Cards.IndexOf(cardsToShuffleTo.Last()); CardController lastCard = cardsToShuffleTo.Last(); lastCard.ViewFSM.SetTextVisibility(true); AnimateShuffle(lastCard, i); shuffleAnimationWaiter.AddFinishable(lastCard.Holder); } if (ShuffleAnimationCamera != null && _shuffleAnimationOriginPoint != null) { shuffleAnimationWaiter.AddFinishable( _shuffleAnimationCamera.AddPositionPingPongTween(_shuffleAnimationCamera.transform.position + Vector3.up * _CardAnimationData.CameraShuffleTweenUpAmount) .SetDuration(_CardAnimationData.DeckShuffleExplosionDuration)); } _Cards.Clear(); _Cards.AddRange(cardsToShuffleTo); shuffleAnimationWaiter.Ready = true; if (CardFlipAudio != null) { CardFlipAudio.PlayOneShot(_cardShuffleClip); StartCoroutine(PlayCardRuffleClip()); } }
private IEnumerator PlayCardRuffleClip() { yield return(new WaitForSeconds(Mathf.Max(0.0f, _CardAnimationData.DeckShuffleExplosionDuration - _cardRuffleClip.length))); CardFlipAudio.PlayOneShot(_cardRuffleClip); }