private void onAddCoins(int coinsAdded, bool isCollectible) { if (isSuppressed) { return; } switch (state) { case CoinHudState.closed: if (!isCollectible) { Service.Get <EventDispatcher>().DispatchEvent(new PlayerScoreEvents.ShowPlayerScore(dataEntityCollection.LocalPlayerSessionId, $"+{coinsAdded}", PlayerScoreEvents.ParticleType.Coins)); } showCoinHud(); remainingCoins += coinsAdded; state = CoinHudState.opening; break; case CoinHudState.opening: case CoinHudState.addingCoins: remainingCoins += coinsAdded; break; case CoinHudState.waitingToClose: CancelInvoke(); remainingCoins += coinsAdded; CoroutineRunner.Start(updateCoinDisplay(), this, "updateXpDisplay"); break; } }
private IEnumerator updateCoinDisplay() { eventDispatcher.DispatchEvent(default(HudEvents.CoinAdditionStart)); state = CoinHudState.addingCoins; showCoinAdding(); startLoopAudio(); float steps = 120f; if ((float)remainingCoins < steps) { while (remainingCoins > 0) { coinCount++; remainingCoins--; CoinText.text = coinCount.ToString(); CoinParticles.Emit(5); yield return(new WaitForSeconds(0.025f)); } } else { int coinGroup = Mathf.CeilToInt((float)remainingCoins / steps); coinCount += coinGroup; remainingCoins -= coinGroup; while (remainingCoins > 0) { if (remainingCoins < coinGroup) { coinCount += remainingCoins; remainingCoins = 0; } else { coinCount += coinGroup; remainingCoins -= coinGroup; } CoinText.text = coinCount.ToString(); CoinParticles.Emit(Mathf.Min(coinGroup, 5)); yield return(new WaitForSeconds(0.025f)); } } stopCoinAdding(); stopLoopAudio(); state = CoinHudState.waitingToClose; eventDispatcher.DispatchEvent(default(HudEvents.CoinAdditionStop)); Invoke("hideCoinHud", CloseTime); }
public void Start() { eventDispatcher = Service.Get <EventDispatcher>(); eventChannel = new EventChannel(eventDispatcher); state = CoinHudState.closed; coinAnimator = GetComponent <Animator>(); remainingCoins = 0; base.gameObject.SetActive(value: false); dataEntityCollection = Service.Get <CPDataEntityCollection>(); DataEntityHandle localPlayerHandle = dataEntityCollection.LocalPlayerHandle; if (!localPlayerHandle.IsNull && dataEntityCollection.HasComponent <PresenceData>(localPlayerHandle)) { setUpCoinCount(localPlayerHandle); } else { eventDispatcher.AddListener <PlayerSpawnedEvents.LocalPlayerSpawned>(onLocalPlayerAdded); } eventDispatcher.AddListener <HudEvents.SuppressCoinDisplay>(onSuppressCoinDisplay); eventDispatcher.AddListener <HudEvents.UnsuppressCoinDisplay>(onUnsuppressCoinDisplay); }
private void hideCoinHud() { state = CoinHudState.closed; coinAnimator.SetBool("isShown", value: false); }