public void ReloadPlayer() { BackGroundAudioVolume = PreferencesFactory.GetFloat("BackGroundAudioVolume", BackGroundAudioVolume, false); EffectAudioVolume = PreferencesFactory.GetFloat("EffectAudioVolume", EffectAudioVolume, false); Players = new PlayerGameItemManager(); Players.Load(0, PlayerCount - 1); // handle auto setup of worlds and levels if (AutoCreateWorlds) { var coinsToUnlockWorlds = WorldUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockWorlds : -1; Worlds = new WorldGameItemManager(); Worlds.Load(1, NumberOfAutoCreatedWorlds, coinsToUnlockWorlds, LoadWorldDatafromResources); // if we have worlds then autocreate levels for each world. if (AutoCreateLevels) { for (var i = 0; i < NumberOfAutoCreatedWorlds; i++) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Worlds.Items[i].Levels = new LevelGameItemManager(); Worlds.Items[i].Levels.Load(WorldLevelNumbers[i].Min, WorldLevelNumbers[i].Max, coinsToUnlock, LoadLevelDatafromResources); } // and assign the selected set of levels Levels = Worlds.Selected.Levels; } } else { // otherwise not automatically setting up worlds so if auto setup of levels then create at root level. if (AutoCreateLevels) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Levels = new LevelGameItemManager(); Levels.Load(1, NumberOfAutoCreatedLevels, coinsToUnlock, LoadLevelDatafromResources); } } // handle auto setup of characters if (AutoCreateCharacters) { Characters = new CharacterGameItemManager(); if (CharacterUnlockMode == GameItem.UnlockModeType.Coins) { Characters.Load(1, NumberOfAutoCreatedCharacters, CoinsToUnlockCharacters, LoadCharacterDatafromResources); } else { Characters.Load(1, NumberOfAutoCreatedCharacters, loadFromResources: LoadCharacterDatafromResources); } } }
/// <summary> /// Main setup routine /// </summary> protected override void GameSetup() { base.GameSetup(); var sb = new System.Text.StringBuilder(); MyDebug.DebugLevel = DebugLevel; sb.Append("GameManager: GameSetup()"); sb.Append("\nApplication.systemLanguage: ").Append(Application.systemLanguage); // secure preferences PreferencesFactory.UseSecurePrefs = SecurePreferences; if (SecurePreferences) { if (string.IsNullOrEmpty(PreferencesPassPhrase)) { Debug.LogWarning("You have not set a custom pass phrase in GameManager | Player Preferences. Please correct for improved security."); } else { PreferencesFactory.PassPhrase = PreferencesPassPhrase; } PreferencesFactory.AutoConvertUnsecurePrefs = AutoConvertUnsecurePrefs; } // Gameplay related properties IsUnlocked = PreferencesFactory.GetInt("IsUnlocked", 0) != 0; IsUserInteractionEnabled = true; IsSplashScreenShown = false; TimesGamePlayed = PreferencesFactory.GetInt("TimesGamePlayed", 0); TimesGamePlayed++; TimesLevelsPlayed = PreferencesFactory.GetInt("TimesLevelsPlayed", 0); TimesPlayedForRatingPrompt = PreferencesFactory.GetInt("TimesPlayedForRatingPrompt", 0); TimesPlayedForRatingPrompt++; sb.Append("\nTimesGamePlayed: ").Append(TimesGamePlayed); sb.Append("\nTimesLevelsPlayed: ").Append(TimesLevelsPlayed); sb.Append("\nTimesPlayedForRatingPrompt: ").Append(TimesPlayedForRatingPrompt); sb.Append("\nApplication.PersistantDataPath: ").Append(Application.persistentDataPath); MyDebug.Log(sb.ToString()); // audio related properties BackGroundAudioVolume = 1; // default if nothing else is set. EffectAudioVolume = 1; // default if nothing else is set. var audioSources = GetComponents <AudioSource>(); if (audioSources.Length > 0) { BackGroundAudioSource = audioSources[0]; BackGroundAudioVolume = BackGroundAudioSource.volume; } if (audioSources.Length > 1) { EffectAudioSources = new AudioSource[audioSources.Length - 1]; Array.Copy(audioSources, 1, EffectAudioSources, 0, audioSources.Length - 1); EffectAudioVolume = EffectAudioSources[0].volume; } BackGroundAudioVolume = PreferencesFactory.GetFloat("BackGroundAudioVolume", BackGroundAudioVolume, false); EffectAudioVolume = PreferencesFactory.GetFloat("EffectAudioVolume", EffectAudioVolume, false); Assert.IsNotNull(Camera.main, "You need a main camera in your scene!"); // display related properties SetDisplayProperties(); // Localisation setup. If nothing stored then use system Language if it exists. Otherwise we will default to English. LocaliseText.AllowedLanguages = SupportedLanguages; // setup players. Assert.IsTrue(PlayerCount >= 1, "You need to specify at least 1 player in GameManager"); Players = new PlayerGameItemManager(); Players.Load(0, PlayerCount - 1); //TODO: Make Obsolete if (WorldUnlockMode == GameItem.UnlockModeType.Coins || LevelUnlockMode == GameItem.UnlockModeType.Coins || CharacterUnlockMode == GameItem.UnlockModeType.Coins) { Debug.LogWarning("GameManager Unlock Modes are deprecated in favour of the more powerful UnlockXxx options in GameItem configuration files and will soon be removed. Change the GameManager settings to Custom to remove this warning and add / configure GameItem configuration files."); } // handle auto setup of worlds and levels Worlds = new WorldGameItemManager(); Levels = new LevelGameItemManager(); Characters = new CharacterGameItemManager(); if (AutoCreateWorlds) { var coinsToUnlockWorlds = WorldUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockWorlds : -1; Worlds.Load(1, NumberOfAutoCreatedWorlds, coinsToUnlockWorlds, LoadWorldDatafromResources); // if we have worlds then autocreate levels for each world. if (AutoCreateLevels) { for (var i = 0; i < NumberOfAutoCreatedWorlds; i++) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Worlds.Items[i].Levels = new LevelGameItemManager(); Worlds.Items[i].Levels.Load(WorldLevelNumbers[i].Min, WorldLevelNumbers[i].Max, coinsToUnlock, LoadLevelDatafromResources); } // and assign the selected set of levels Levels = Worlds.Selected.Levels; } } else { // otherwise not automatically setting up worlds so if auto setup of levels then create at root level. if (AutoCreateLevels) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Levels.Load(1, NumberOfAutoCreatedLevels, coinsToUnlock, LoadLevelDatafromResources); } } // handle auto setup of characters if (AutoCreateCharacters) { if (CharacterUnlockMode == GameItem.UnlockModeType.Coins) { Characters.Load(1, NumberOfAutoCreatedCharacters, CoinsToUnlockCharacters, LoadCharacterDatafromResources); } else { Characters.Load(1, NumberOfAutoCreatedCharacters, loadFromResources: LoadCharacterDatafromResources); } } // coroutine to check for display changes (don't need to do this every frame) if (!Mathf.Approximately(DisplayChangeCheckDelay, 0)) { StartCoroutine(CheckForDisplayChanges()); } // flag as initialised IsInitialised = true; }