Esempio n. 1
0
        // Update the player's progress based on the level they just played
        private void UpdateGameProgress()
        {
            Debug.Log("--- Overworld : Update Game Progress ---");

            // Fade in the camera
            _screenFader.FadeIn();

            // Center the camera on the player's base (is overriden later if levelInfo is loaded)
            _cameraController.SetCameraPosition(_playerBase.position);

            // No level progress data was found
            var levelProgressData = LevelProgress.Data;

            if (levelProgressData == null)
            {
                return;
            }

            // No level info data was found
            var levelInfo = GetLevelInfoBySceneName(levelProgressData.SceneName);

            if (levelInfo == null)
            {
                return;
            }

            // Set the level as 'Complete' if it was passed and was not previously finished
            if (levelProgressData.LevelPassed && levelInfo.LevelState == LevelState.Unlocked)
            {
                levelInfo.CompleteLevel();
            }

            // Add any item rewards
            RewardItems(levelProgressData, levelInfo);

            // Add resource rewards
            ItemProgress.AddResources(levelProgressData.Resources);

            // Update tower lifetime stats
            TowerProgress.UpdateTowerLifetimeStats(levelProgressData.TowerStats);

            // Update highest level defeated
            levelInfo.UpdateHighestWaveDefeated(levelProgressData.WavesDefeated);

            // Open the level finished window
            _windowLevelFinished.WindowOpen(levelProgressData);

            // Set the camera to the location of the level on the map
            _cameraController.SetCameraPosition(levelInfo.transform.position);

            // Reset the progress data after it has been used
            LevelProgress.ResetLevelProgress();
        }