void Update() { if (!playerStats.playerStatsLoaded) { playerStats = FindObjectOfType <PlayerStatistics>(); } if (firstTimeLoad && playerStats.playerStatsLoaded) { coinsText.text = playerStats.playerCoins.ToString(); PlayerStatistics.Chapter chapterData = playerStats.chaptersList[chapterIndex]; List <PlayerStatistics.Level> levelsInChapter = chapterData.LevelsInChapter; int numLevels = levelsInChapter.Count; for (int i = numLevels - 1; i >= 0; i--) { generateLevelItem(levelsInChapter[i].IsPlayed, levelsInChapter[i].IsPlaying, levelsInChapter[i].IsLocked, levelsInChapter[i].LevelIndex, levelsInChapter[i].PersonalBestTime, levelsInChapter[i].CoinsAcquiredInLevel, levelsInChapter[i].CoinsInLevel); } if (playerStats.highestChapter > chapterIndex) { scrollView.verticalNormalizedPosition = 1f; } else { Debug.Log("Highest level in " + chapterIndex + "is: " + playerStats.highestLevel); scrollView.verticalNormalizedPosition = (float)(playerStats.highestLevel) / 10f; } firstTimeLoad = false; } }
private void UpdateAndUnlockNextLevel(int currentChapterIndex, int currentLevelIndex, float timeTaken) { playerStats.playerCoins += currentCoinsAcquired; PlayerStatistics.Level currentLevelObj = playerStats.chaptersList[currentChapterIndex].LevelsInChapter[currentLevelIndex]; currentLevelObj.IsPlayed = true; currentLevelObj.IsPlaying = false; currentLevelObj.PersonalBestTime = Mathf.Min(currentLevelObj.PersonalBestTime, timeTaken); currentLevelObj.CoinsInLevel = coinsInScene; currentLevelObj.CoinsAcquiredInLevel = currentCoinsAcquired; playerStats.chaptersList[currentChapterIndex].LevelsInChapter[currentLevelIndex] = currentLevelObj; if (currentLevelIndex == playerStats.chaptersList[currentChapterIndex].LevelsInChapter.Count - 1) { if (currentChapterIndex == playerStats.chaptersList.Count - 1) { } else { PlayerStatistics.Chapter nextChapterObj = playerStats.chaptersList[currentChapterIndex + 1]; nextChapterObj.IsLocked = false; playerStats.chaptersList[currentChapterIndex + 1] = nextChapterObj; PlayerStatistics.Level nextLevelObj = playerStats.chaptersList[currentChapterIndex + 1].LevelsInChapter[0]; playerStats.highestChapter = PersistentInformation.CurrentChapter = currentChapterIndex + 1; playerStats.highestLevel = 0; if (!nextLevelObj.IsPlayed) { nextLevelObj.IsPlaying = true; } nextLevelObj.IsLocked = false; playerStats.chaptersList[currentChapterIndex + 1].LevelsInChapter[0] = nextLevelObj; } } else { PlayerStatistics.Level nextLevelObj = playerStats.chaptersList[currentChapterIndex].LevelsInChapter[currentLevelIndex + 1]; nextLevelObj.IsPlaying = true; nextLevelObj.IsLocked = false; playerStats.chaptersList[currentChapterIndex].LevelsInChapter[currentLevelIndex + 1] = nextLevelObj; playerStats.highestLevel = currentLevelIndex + 1; } }