Example #1
0
        private void RefreshScoreRecord(SongItemView songItem)
        {
            int crown = 0, star = 0;

            //set highscore
            star  = HighScoreManager.Instance.GetHighScore(songItem.Model.storeID, ScoreType.Star);
            crown = HighScoreManager.Instance.GetHighScore(songItem.Model.storeID, ScoreType.Crown);
            //print("Item: " + songItem.Model.storeID + " crown: " + crown + " star: " + star);
            if (crown > 0)
            {
                songItem.SetNumCrowns(crown);
            }
            else
            {
                songItem.SetNumStars(star);
            }
        }
        private void DisplaySongResult()
        {
            MidiPlayer.Instance.ShouldPlay = true;
            animatorBestScoreEffect.gameObject.SetActive(false);

            score = Counter.GetQuantity(Counter.KeyScore);
            star  = Mathf.Clamp(Counter.GetQuantity(Counter.KeyStar), 0, 3);
            crown = Counter.GetQuantity(Counter.KeyStar) - 3;
            if (crown < 0)
            {
                crown = 0;
            }

            //return 1 live for user if they haven't score any point at all
            if (score <= 0)
            {
                ProfileHelper.Instance.CurrentLife += 1;
            }

            //set song title
            songInfo.SetTitle(GameManager.Instance.SessionData.currentLevel.songData.name);

            int animatingScore = 0;

            //update score with a little animation
            DOTween.To(() => animatingScore, x => animatingScore = x, score, 1f)
            .OnUpdate(() => {
                lbScore.text = animatingScore.ToString();
                //MidiPlayer.Instance.PlayPianoNote(SOUND_PIANO_FINISHED_SCORING);
            })
            .SetDelay(0.5f)
            //.OnComplete(() => { MidiPlayer.Instance.PlayPianoNote(SOUND_PIANO_FINISHED_SCORING); })
            .Play();

            if (crown > 0)
            {
                songInfo.SetNumCrowns(crown);
            }
            else
            {
                songInfo.SetNumStars(star);
            }

            string songID         = GameManager.Instance.SessionData.currentLevel.songData.storeID;
            bool   isNewBestScore = false;

            //update last play levels
            GameManager.Instance.StoreLastPlayLevel();

            //update highscore
            if (HighScoreManager.Instance.UpdateHighScore(songID, score))
            {
                isNewBestScore = true;
                //check and show newly unlocked songs
                Timing.RunCoroutine(C_ShowUnlockedSongs(2.5f));
                //only update crown and star if getting a new highscore
                if (crown > 0)
                {
                    if (HighScoreManager.Instance.UpdateHighScore(songID, crown, ScoreType.Crown))
                    {
                        //if this is the first time reach 3 crowns, also set achievement
                        if (crown == 3)
                        {
                            AchievementHelper.Instance.LogAchievement("song6Stars");
                        }
                    }
                    ;
                }
                if (star > 0)
                {
                    if (HighScoreManager.Instance.UpdateHighScore(songID, star, ScoreType.Star))
                    {
                        //if this is the first time reach 3 stars, also set achievement
                        if (star == 3)
                        {
                            AchievementHelper.Instance.LogAchievement("song3Stars");
                        }
                    }
                }
            }

            //MidiPlayer.Instance.ShouldPlay = false;
            AnalyticsHelper.Instance.LogLevelFinished(GameManager.Instance.SessionData.currentLevel.songData.name, score, star, crown);
            MessageBus.Annouce(saveUserDataMessage);

            ProfileHelper.Instance.PushUserData(true);

            if (!isNewBestScore)
            {
                lbHighScore.text = Localization.Get("maingame_highscore") + " " + HighScoreManager.Instance.GetHighScore(songID).ToString();
            }
            else
            {
                lbHighScore.text = "";
                if (score > 0)
                {
                    Timing.RunCoroutine(C_ShowNewBest(2f));
                }
            }

            //achievement logging
            if (crown == 3)
            {
                AchievementHelper.Instance.LogAchievement("turn6Stars");
            }
            if (star == 3)
            {
                AchievementHelper.Instance.LogAchievement("turn3Stars");
            }
            GameManager.Instance.SaveAchievementValue();
            MessageBus.Annouce(gameDataChangedMessage);

            float delaySceneAnimation = isNewBestScore ? 3f : 2f;

            Timing.RunCoroutine(C_ShowSceneAnimation(delaySceneAnimation));

            UnityAdsHelper.Instance.ShowInterstitialAds(false);
            AdmobAdsHelper.Instance.ShowInterstitialAds();
        }