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);
            }
        }
    }
Пример #2
0
        /// <summary>
        /// Load this item from perferences within the context of the specified GameItem
        /// </summary>
        public void LoadFromPrefs()
        {
            if (Configuration.CounterType == CounterConfiguration.CounterTypeEnum.Int)
            {
                if (Configuration.Save == CounterConfiguration.SaveType.None)
                {
                    IntAmountSaved = IntAmount = Configuration.IntDefault;
                }
                else
                {
                    IntAmountSaved = IntAmount = PreferencesFactory.GetInt(_prefsKey, Configuration.IntDefault);
                }

                if (Configuration.SaveBest == CounterConfiguration.SaveType.None)
                {
                    IntAmountBestSaved = IntAmountBest = Configuration.IntDefault;
                }
                else
                {
                    IntAmountBestSaved = IntAmountBest = PreferencesFactory.GetInt(_prefsKeyBest, Configuration.IntDefault);
                }
            }
            else
            {
                if (Configuration.Save == CounterConfiguration.SaveType.None)
                {
                    FloatAmountSaved = FloatAmount = Configuration.FloatDefault;
                }
                else
                {
                    FloatAmountSaved = FloatAmount = PreferencesFactory.GetFloat(_prefsKey, Configuration.FloatDefault);
                }


                if (Configuration.SaveBest == CounterConfiguration.SaveType.None)
                {
                    FloatAmountBestSaved = FloatAmountBest = Configuration.FloatDefault;
                }
                else
                {
                    FloatAmountBestSaved = FloatAmountBest = PreferencesFactory.GetFloat(_prefsKeyBest, Configuration.FloatDefault);
                }
            }
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
 /// <summary>
 /// Load saved values from preferences or set to default if not found.
 /// </summary>
 /// <param name="prefix"></param>
 /// <param name="useSecurePrefs"></param>
 public void Load(string prefix = "", bool?useSecurePrefs = null)
 {
     foreach (var variable in BoolVariables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetBool(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs);
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
     foreach (var variable in FloatVariables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetFloat(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs);
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
     foreach (var variable in IntVariables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetInt(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs);
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
     foreach (var variable in StringVariables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetString(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs);
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
     foreach (var variable in Vector2Variables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetVector2(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs) ?? Vector2.zero;
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
     foreach (var variable in Vector3Variables)
     {
         if (variable.PersistChanges)
         {
             variable.Value = PreferencesFactory.GetVector3(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs) ?? Vector3.zero;
         }
         else
         {
             variable.Value = variable.DefaultValue;
         }
     }
 }