示例#1
0
        // Delegate method triggered when a new scene is loaded.
        private void NewSceneLoaded(Scene arg0, LoadSceneMode arg1)
        {
            // Reset time scale if game was paused.
            Time.timeScale = 1.0f;

            // Reset information about the loaded scene.
            isMainMenu = false;
            mainMenu   = null;

            isWorldMap = false;
            worldmap   = null;

            levelMgr = null;

            AudioClip musicToPlay = null;

            // Setup transition manager of the current scene.
            ui = GameObject.FindGameObjectWithTag("UI");
            if (ui)
            {
                transitionManager = ui.transform.Find("TransitionPanel").GetComponent <TransitionManager>();
            }

            // Load main menu :
            if (arg0.buildIndex == mainMenuIndex)
            {
                // Here we can create new game or load existing game, we can also change settings...
                isMainMenu = true;

                mainMenu    = GameObject.Find("MainMenuUI").GetComponent <MainMenuManager>();
                musicToPlay = audioMgr.mainMenuMusic;
            }

            // Load world map :
            else if (arg0.buildIndex == worldMapIndex)
            {
                // Here we can move on the world map and enter in a level or access to an another world.

                isWorldMap = true;

                if (playerProgress != null)
                {
                    currentWorldIndex = playerProgress.currentWorldIndex;
                }

                // for debug only.
                else
                {
                    // Load first save.
                    playerProgress    = SaveLoadManager.LoadPlayerProgress(saveSlotSelected);
                    currentWorldIndex = playerProgress.currentWorldIndex;
                }

                worldmap = GameObject.Find("WorldMap").GetComponent <WorldMapManager>();
                StartCoroutine(worldmap.SetupMap(playerProgress));

                musicToPlay = audioMgr.worldMapMusic;
            }

            // Load a level :
            else
            {
                // Try to get the level manager of this level.
                GameObject levelManager = GameObject.FindGameObjectWithTag("LevelManager");
                if (levelManager)
                {
                    levelMgr = levelManager.GetComponent <LevelManager>();
                    levelMgr.StartCoroutine(levelMgr.DisplayLevelIntro(arg0.name));

                    musicToPlay = levelMgr.data.levelMusic;
                }
            }

            if (audioMgr)
            {
                audioMgr.PlayMusic(musicToPlay);
            }
            else
            {
                Debug.LogWarning("No audio manager found in this level.");
            }
        }
示例#2
0
        /// <summary>
        /// Store the current level progress and save it.
        /// </summary>
        /// <param name="feathersCollected"></param>
        /// <param name="itemsFound"></param>
        public void SaveLevelProgress(int feathersCollected, bool[] itemsFound, bool treasureFound)
        {
            // Debug.
            if (playerProgress == null)
            {
                return;
            }

            LevelProgress levelProgress = null;

            // Save found. Update for the best values.
            if (playerProgress.worldProgress[currentWorldIndex].finishedLevels.TryGetValue(currentLevelIndex, out levelProgress))
            {
                levelProgress.feathersCollected = Mathf.Max(feathersCollected, levelProgress.feathersCollected);
            }

            // level finished for the first time, create and add new entry with the corect amount of exits and feathers collected.
            else
            {
                levelProgress = new LevelProgress(levelMgr.data.exitCount, feathersCollected);

                playerProgress.worldProgress[currentWorldIndex].finishedLevels.Add(currentLevelIndex, levelProgress);
            }

            // Update items :
            for (int i = 0; i < levelProgress.specialItemsFound.Length; i++)
            {
                // Don't update item if already found.
                if (levelProgress.specialItemsFound[i])
                {
                    continue;
                }

                // Update if item has been found.
                if (itemsFound[i])
                {
                    levelProgress.specialItemsFound[i] = true;

                    // Sunflower seed obtained.
                    if (i == 3)
                    {
                        playerProgress.worldProgress[currentWorldIndex].sunFlowerSeedCollected++;
                    }
                }
            }

            // Update treasure if exist and hasn't already save.
            if (treasureFound && !levelProgress.treasureFound)
            {
                levelProgress.treasureFound = treasureFound;
                playerProgress.treasuresFound.Add(currentWorldIndex + "-" + currentLevelIndex, true);
            }

            // Update exit taken.
            levelProgress.exits[levelMgr.ExitTaken] = true;

            // Cumulate stats.
            playerProgress.deathCount += levelMgr.DeathCount;
            playerProgress.timePlayed += levelMgr.Timer;

            // TODO save best time on a specific level.

            // Save.
            SaveLoadManager.SavePlayerProgress(playerProgress, saveSlotSelected);
        }