public static VersionGeneratorArgs GetAllVersions()
        {
            VersionGeneratorArgs returnArgs = new VersionGeneratorArgs();
            Type versionInterface           = typeof(ISettingsVersionGenerator);
            var  types = AppDomain.CurrentDomain.GetAssemblies()
                         .SelectMany(x => x.GetTypes())
                         .Where(x => x.IsClass && !x.IsAbstract && versionInterface.IsAssignableFrom(x));
            string errorMessage;

            foreach (Type versionType in types)
            {
                if (returnArgs.AddVersion(Activator.CreateInstance(versionType) as ISettingsVersionGenerator, out errorMessage) == false)
                {
                    Debug.LogWarning(errorMessage);
                }
            }
            return(returnArgs);
        }
        private static void WriteAllSettingsVersions(TextWriter writer, int numTabs, VersionGeneratorArgs versionsArgs)
        {
            // Write the comment for AllSettingsVersions
            WriteTooltipComment(writer, numTabs, "Array of all the <see cref=\"ISettingsVersion\"/> detected in this project.", "Used as reference in the properties.");

            // Declare AllSettingsVersions array
            numTabs = WriteStartEncapsulation(writer, numTabs, "private readonly ISettingsVersion[] AllSettingsVersions = new ISettingsVersion[]");

            // Go through all the versions
            foreach (ISettingsVersionGenerator version in versionsArgs)
            {
                // Write out the version's class' default constructor
                version.WriteCodeForConstructor(writer, numTabs);
                writer.WriteLine(',');
            }

            // End array
            numTabs = WriteEndEncapsulation(writer, numTabs, true);
        }
        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);
        }
        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);
        }