Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 private void hideCoinHud()
 {
     state = CoinHudState.closed;
     coinAnimator.SetBool("isShown", value: false);
 }