An attempt at creating a nicely styled mod configuration utility for Len's Island.
Disclaimer: I have never worked with Unity's UI system before, so this could be completely crap.
Manual installation of BepInEx is required until mod managers add support for Len's Island.
To use IslandConfig for configuring your BepInEx mods ingame:
- Download the latest release.
- Extract the
plugins
folder to the gameBepInEx
folder.
You only need the plugins
folder from the ZIP file for manual installation.
By default, IslandConfig will generate appropriate UI elements matching the structure of your BepInEx config bindings.
You do not need to add a dependency on this package unless you wish to have control over how the UI gets generated.
dotnet nuget add source https://nuget.pkg.github.com/csh/index.json --name "github/csh" --username <GITHUB_USERNAME> --password <GITHUB_PAT>
You must generate a personal access token (classic) with the read:packages
scope to use this feed.
You can run the command below or add a <PackageReference>
to your csproj file, whatever floats your boat.
dotnet add package IslandConfig --version 0.1.0
<PackageReference Include="IslandConfig" Version="0.*" PrivateAssets="all" />
First, you will need to add at least a soft dependency on IslandConfig to ensure BepInEx loads things in the correct order.
If you are using a soft dependency you will need to check the Chainloader
for the presence of IslandConfig at runtime.
[BepInDependency("com.smrkn.island-config", BepInDependency.DependencyFlags.SoftDependency)]
The example code below uses a hard dependency for simplicity.
[BepInPlugin("com.smrkn.example-mod", "IslandConfig Example Mod", "0.1.0")]
[BepInDependency("com.smrkn.island-config")]
public class ExampleMod : BaseUnityPlugin
{
public static ConfigEntry<bool> EnableCoolFeature;
public static ConfigEntry<bool> EnableDebugMode;
private void Awake()
{
/*
* Create a configuration file that looks like this:
*
* [General]
* Debug = false
* CoolFeature1 = true
*/
EnableDebugMode = Config.Bind("General", "Debug", false);
EnableCoolFeature = Config.Bind("General", "CoolFeature1", true);
// If changing a value requires more complex logic than an if check somewhere
// then you should subscribe to the SettingChanged event
EnableCoolFeature.SettingChanged += ToggleCoolFeature;
IslandConfig.Register(builder =>
{
// Only CoolFeature1 will be featured in the generated config UI
builder.WithCheckbox(
EnableCoolFeature,
// Define a custom section for grouping settings in the UI
section: "My First Mod",
// Define a custom label that will appear on the UI
label: "Enable Cool Feature 1",
// Define a custom description that will appear when the setting is hovered in the UI
description: "Enabling this will make something cool happen."
);
});
// Your init logic
}
private void ToggleCoolFeature(object sender, EventArgs e)
{
// Do something in response to the config changing, maybe enable/disable a specific Harmony patch.
}
private void OnDestroy()
{
/*
* Notify IslandConfig that the plugin is being unloaded.
*
* IslandConfig tracks plugins and configuration entries using weak references so that if
* a plugin is unloaded the relevant config entries are disposed of automatically.
*
* IslandConfig was designed with ScriptEngine from BepInEx.Debug in mind, allowing developers
* to rapidly iterate with hot-reload capabilities, however this relies on Unity's garbage collector
* disposing of the plugin object before the hot-reload completes to ensure correctness.
*
* Therefore manually unregistering is preferred, but not *strictly* necessary.
*/
IslandConfig.Unregister();
EnableCoolFeature.SettingChanged -= ToggleCoolFeature;
}
}
More examples will be added in future as the API expands.