public void UpdateSettingArgs(int versionArrayIndex, SettingsGeneratorArgs args)
        {
            string errorMessage;

            // Check if there are any settings to remove
            string[] keysToRemove = GetKeysToRemove();
            if ((keysToRemove != null) && (keysToRemove.Length > 1))
            {
                // If so, remove them from args
                foreach (string key in keysToRemove)
                {
                    if (args.RemoveSetting(key, out errorMessage) == false)
                    {
                        Debug.Log(errorMessage);
                    }
                }
            }

            // If so, remove them from args
            foreach (IGenerator newGenerator in allSettingsGenerator.Values)
            {
                if (args.AddSetting(versionArrayIndex, newGenerator, out errorMessage) == false)
                {
                    Debug.Log(errorMessage);
                }
            }
        }
        public void AutoGenerateSettingsCode()
        {
            // First grab all the versions
            VersionGeneratorArgs versionsArgs = GameSettingsGenerator.GetAllVersions();

            // Setup namespaces and arguments
            int index = 0;
            NamespaceGeneratorArgs usingsArgs   = new NamespaceGeneratorArgs();
            SettingsGeneratorArgs  settingsArgs = new SettingsGeneratorArgs();

            foreach (ISettingsVersionGenerator version in versionsArgs)
            {
                version.UpdateNamespaceArgs(usingsArgs);
                version.UpdateSettingArgs(index, settingsArgs);
                ++index;
            }

            // Next, write to a file
            GameSettingsGenerator.WriteCode(versionsArgs, usingsArgs, settingsArgs);
        }
        private static void WriteAllSingleSettings(TextWriter writer, int numTabs, SettingsGeneratorArgs settingsArgs)
        {
            // Write the comment for allSingleSettings
            WriteTooltipComment(writer, numTabs, "Array cache used by <see cref=\"AllSingleSettings\"/>.");

            // Declare allSingleSettings array member variable
            WriteLine(writer, numTabs, "private IStoredSetting[] allSingleSettings = null;");
            writer.WriteLine();

            // Write the comment for AllSingleSettings
            WriteTooltipComment(writer, numTabs, "Array of <see cref=\"IStoredSetting\"/> that has a Property in this class.", "Used for collective saving and retrieval of settings.");

            // Declare AllSingleSettings property
            numTabs = WriteStartEncapsulation(writer, numTabs, "private IStoredSetting[] AllSingleSettings");

            // Start get
            numTabs = WriteStartEncapsulation(writer, numTabs, "get");

            // Start if
            numTabs = WriteStartEncapsulation(writer, numTabs, "if(allSingleSettings == null)");

            // Start intializing array
            numTabs = WriteStartEncapsulation(writer, numTabs, "allSingleSettings = new IStoredSetting[]", false);

            // Go through each group
            foreach (KeyValuePair <int, ICollection <SettingsGeneratorArgs.SingleSettingsInfo> > groupOfSettings in settingsArgs)
            {
                // Start a region
                writer.WriteLine();
                WriteStartOfLine(writer, numTabs, "#region ISingleSettings from version ");
                writer.WriteLine(groupOfSettings.Key);

                // Go through all the settings
                foreach (SettingsGeneratorArgs.SingleSettingsInfo setting in groupOfSettings.Value)
                {
                    if (setting.isStoredSetting == true)
                    {
                        // Write the setting
                        WriteTabs(writer, numTabs);
                        setting.generator.WriteCodeToInstance(writer, setting.versionArrayIndex, false);
                        writer.WriteLine(',');
                    }
                }

                // End region
                WriteLine(writer, numTabs, "#endregion");
            }

            // End array
            numTabs = WriteEndEncapsulation(writer, numTabs, true);

            // End if
            numTabs = WriteEndEncapsulation(writer, numTabs);

            // Write return statement
            WriteLine(writer, numTabs, "return allSingleSettings;");

            // End get
            numTabs = WriteEndEncapsulation(writer, numTabs);

            // End AllSingleSettings property
            numTabs = WriteEndEncapsulation(writer, numTabs);
        }
        private static void WriteAllSettingsProperties(TextWriter writer, int numTabs, SettingsGeneratorArgs settingsArgs)
        {
            // Go through each group
            foreach (KeyValuePair <int, ICollection <SettingsGeneratorArgs.SingleSettingsInfo> > groupOfSettings in settingsArgs)
            {
                // Declare region
                writer.WriteLine();
                WriteStartOfLine(writer, numTabs, "#region Properties from AppVersion ");
                writer.Write(groupOfSettings.Key);

                // Go through all the settings
                foreach (SettingsGeneratorArgs.SingleSettingsInfo setting in groupOfSettings.Value)
                {
                    // Write a line
                    writer.WriteLine();

                    // Write the setting
                    setting.generator.WriteCodeToAccessSetting(writer, numTabs, setting.versionArrayIndex);
                }

                // End region
                WriteLine(writer, numTabs, "#endregion");
            }
        }
        public static void WriteCode(VersionGeneratorArgs versionsArgs, NamespaceGeneratorArgs usingsArgs, SettingsGeneratorArgs settingsArgs)
        {
            int numTabs = 0;

            using (TextWriter writer = new StreamWriter(GameSettingsFullPath, false, Encoding.UTF8))
            {
                // List out the namespace we're using
                WriteAllUsings(writer, numTabs, usingsArgs);

                // Declare the current namespace
                numTabs = WriteStartEncapsulation(writer, numTabs, "namespace OmiyaGames.Settings");

                // Start the class
                WriteTooltipComment(writer, numTabs, "This code is auto-generated. All changes will be overwritten!");
                numTabs = WriteStartEncapsulation(writer, numTabs, "public partial class GameSettings : Global.ISingletonScript");

                // Write out the array of versions
                WriteLine(writer, numTabs, "#region Private Arrays");
                WriteAllSettingsVersions(writer, numTabs, versionsArgs);
                writer.WriteLine();

                // Write out the array of single settings
                WriteAllSingleSettings(writer, numTabs, settingsArgs);
                WriteLine(writer, numTabs, "#endregion");
                writer.WriteLine();

                // Write AppVersion property
                WriteAppVersionProperty(writer, numTabs);

                // Write out the list of settings
                WriteAllSettingsProperties(writer, numTabs, settingsArgs);

                // End the class
                numTabs = WriteEndEncapsulation(writer, numTabs);

                // End the namespace
                numTabs = WriteEndEncapsulation(writer, numTabs);
            }
            AssetDatabase.ImportAsset(GameSettingsUnityPath, ImportAssetOptions.ForceUpdate);
        }