Auto Config

Updated a month ago

Auto Config: Quick and Easy Configuration Management

The Auto Config feature allows you to rapidly create different types of configuration settings for your Unity mod. Whether you need sliders, toggles, or other common UI elements, AGoodNameLibrary simplifies the process.

Example Usage

using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

namespace testMod
{
    [BepInPlugin(PLUGIN_GUID, PLUGIN_NAME, PLUGIN_VERSION)]
    public class Plugin : BaseUnityPlugin
    {
        public const string PLUGIN_GUID = "com.yourname.testMod";
        public const string PLUGIN_NAME = "testMod";
        public const string PLUGIN_VERSION = "1.0.0";

        internal static ConfigFile config; // Creates the config file
        internal static ConfigEntry<float> m_ConfigEntry; // Config variable for the slider value

        public void Awake()
        {
            config = Config; // Assigns the config file

            // Log that the plugin has been loaded
            Logger.LogInfo($"Plugin {PLUGIN_GUID} is loaded!");

            // Create a slider in the config file:
            // - ref m_ConfigEntry: A reference to the config variable
            // - config: The config file to store the setting
            // - "testing config": The section name in the config file
            // - "its testing": A description of the config setting
            // - 1f: Default value
            // - 1f: Minimum value
            // - 2f: Maximum value
            AGoodNameLib.auto_config.Slider<float>(ref m_ConfigEntry, config, "testing config", "its testing", 1f, 1f, 2f);

            // Initialize Harmony and apply patches
            var harmony = new Harmony(PLUGIN_GUID);
            harmony.PatchAll(typeof(Patches));
        }
    }
}