/**
         * <summary>Gets the options values associated with a specific profile.</summary>
         * <param name = "profileID">A unique identifier for the profile to save to</param>
         * <param name = "showLog">If True, the details of this save will be printed in the Console window</param>
         * <param name = "doSave">If True, and if the profile had no OptionsData to read, then new values will be saved to it</param>
         * <returns>An instance of OptionsData containing the profile's options</returns>
         */
        public static OptionsData LoadPrefsFromID(int profileID, bool showLog = false, bool doSave = true)
        {
            if (DoesProfileIDExist(profileID))
            {
                string optionsSerialized = OptionsFileHandler.LoadOptions(profileID, showLog);
                if (!string.IsNullOrEmpty(optionsSerialized))
                {
                    return(Serializer.DeserializeOptionsData(optionsSerialized));
                }
            }

            // No data exists, so create new
            if (KickStarter.settingsManager == null)
            {
                return(null);
            }

            OptionsData _optionsData = new OptionsData(KickStarter.settingsManager.defaultLanguage, KickStarter.settingsManager.defaultShowSubtitles, KickStarter.settingsManager.defaultSfxVolume, KickStarter.settingsManager.defaultMusicVolume, KickStarter.settingsManager.defaultSpeechVolume, profileID);

            if (doSave)
            {
                optionsData = _optionsData;
                SavePrefs();
            }

            return(_optionsData);
        }
        /**
         * <summary>Gets the options values associated with a specific profile.</summary>
         * <param name = "ID">A unique identifier for the profile to save to</param>
         * <param name = "showLog">If True, the details of this save will be printed in the Console window</param>
         * <param name = "doSave">If True, and if the profile had no OptionsData to read, then new values will be saved to it</param>
         * <returns>An instance of OptionsData containing the profile's options</returns>
         */
        public static OptionsData LoadPrefsFromID(int ID, bool showLog = false, bool doSave = true)
        {
            if (PlayerPrefs.HasKey(GetPrefKeyName(ID)))
            {
                string optionsSerialized = PlayerPrefs.GetString(GetPrefKeyName(ID));
                if (optionsSerialized != null && optionsSerialized.Length > 0)
                {
                    if (showLog)
                    {
                        ACDebug.Log("PlayerPrefs Key '" + GetPrefKeyName(ID) + "' loaded");
                    }
                    return(Serializer.DeserializeOptionsData(optionsSerialized));
                }
            }

            // No data exists, so create new
            OptionsData _optionsData = new OptionsData(KickStarter.settingsManager.defaultLanguage, KickStarter.settingsManager.defaultShowSubtitles, KickStarter.settingsManager.defaultSfxVolume, KickStarter.settingsManager.defaultMusicVolume, KickStarter.settingsManager.defaultSpeechVolume, ID);

            if (doSave)
            {
                optionsData = _optionsData;
                SavePrefs();
            }

            return(_optionsData);
        }
Exemple #3
0
        /**
         * <summary>Gets the options values associated with a specific profile.</summary>
         * <param name = "profileID">A unique identifier for the profile to save to</param>
         * <param name = "showLog">If True, the details of this save will be printed in the Console window</param>
         * <param name = "doSave">If True, and if the profile had no OptionsData to read, then new values will be saved to it</param>
         * <returns>An instance of OptionsData containing the profile's options</returns>
         */
        public static OptionsData LoadPrefsFromID(int profileID, bool showLog = false, bool doSave = true)
        {
            if (DoesProfileIDExist(profileID))
            {
                string optionsSerialized = OptionsFileHandler.LoadOptions(profileID, showLog);
                if (!string.IsNullOrEmpty(optionsSerialized))
                {
                    try
                    {
                        return(Serializer.DeserializeOptionsData(optionsSerialized));
                    }
                    catch (System.Exception e)
                    {
                        ACDebug.LogWarning("Error retrieving OptionsData for profile #" + profileID + " - rebuilding..\nException: " + e);

                        OptionsData fallbackOptionsData = new OptionsData(profileID);
                        if (KickStarter.settingsManager != null)
                        {
                            fallbackOptionsData = new OptionsData(KickStarter.settingsManager.defaultLanguage,
                                                                  KickStarter.settingsManager.defaultVoiceLanguage,
                                                                  KickStarter.settingsManager.defaultShowSubtitles,
                                                                  KickStarter.settingsManager.defaultSfxVolume,
                                                                  KickStarter.settingsManager.defaultMusicVolume,
                                                                  KickStarter.settingsManager.defaultSpeechVolume,
                                                                  profileID);
                        }
                        SavePrefsToID(profileID, fallbackOptionsData);
                        return(fallbackOptionsData);
                    }
                }
            }

            // No data exists, so create new
            if (KickStarter.settingsManager == null)
            {
                return(null);
            }

            OptionsData _optionsData = new OptionsData(KickStarter.settingsManager.defaultLanguage, KickStarter.settingsManager.defaultVoiceLanguage, KickStarter.settingsManager.defaultShowSubtitles, KickStarter.settingsManager.defaultSfxVolume, KickStarter.settingsManager.defaultMusicVolume, KickStarter.settingsManager.defaultSpeechVolume, profileID);

            if (doSave)
            {
                optionsData = _optionsData;
                SavePrefs();
            }

            return(_optionsData);
        }