Create Mod Settings - piotrulos/MSCModLoader GitHub Wiki

Mod Settings

Mod settings need to be created in main Mod class by creating function using Setup.ModSettings

public class MyMod1 : Mod
{
    public override string ID => "MyMod1"; 
    public override string Name => "Testing";
    public override string Author => "piotrulos";
    public override string Version => "1.0";
    public override string Description => "";
    
    public override void ModSetup()
    {       
        //(...)
        SetupFunction(Setup.ModSettings, Mod_Settings);
    }
    private void Mod_Settings()
    {
        // All settings should be created here
    } 
}

If you want to update some things controlled by settings when settings valued are loaded from save, you need to also createSetup.ModSettingsLoaded

public class MyMod1 : Mod
{
    public override string ID => "MyMod1"; 
    public override string Name => "Testing";
    public override string Author => "piotrulos";
    public override string Version => "1.0";
    public override string Description => "";
       
    public override void ModSetup()
    {
        //(...)
        SetupFunction(Setup.ModSettingsLoaded, Mod_SettingsLoaded);
    }
  
    private void Mod_SettingsLoaded()
    {
        // Call some functions here to update stuff when settings values are loaded
    } 
}

Mod Settings

In version 1.3 old constructor based settings (V1) are hard obsoleted, please switch to current (V3) format of creating settings to futureproof your mods

SettingsSlider and SettingsSliderInt

Used to add slider to mod settings

SettingsSliderInt - Accepts integer values, can also show values as text from string[] array.

AddSlider(string settingID, string name, int minValue, int maxValue, int value = 0, Action onValueChanged = null, string[] textValues = null, bool visibleByDefault = true)

settingID - unique setting ID
name - Name of the slider (visible in settings)
minValue - minimum value (slider range)
maxValue - maximum value (slider range)
value - default value of slider (default is 0)
(Optional) onValueChanged - Do something when value changed (set to null if not needed)
(Optional) textValues - Array of text values (set to null if not needed)
(Optional) visibleByDefault - is setting visible by default

* SettingsSlider - Accepts float values.

AddSlider(string settingID, string name, float minValue, float maxValue, float value = 0f, Action onValueChanged = null, int decimalPoints = 2, bool visibleByDefault = true)

similar values to SettingsSliderInt except:
(Optional) decimalPoints - how many decimal points have float value (default 2)

Usage Examples

SettingsSlider my_slider;
            
private void Mod_Settings()
{
    Settings.AddHeader("This is slider test");
    my_slider = Settings.AddSlider("mySlider", "This is my slider", 0f, 50f, 5f);
}

Result
Float slider with range from 0 to 50 with default value as 5f
obraz

SettingsSliderInt my_slider;
string[] sliderValues = new string[4] { "Something", "Something2", "Something3", "Something4" };

private void Mod_Settings()
{
    Settings.AddHeader("This is slider test");
    my_slider = Settings.AddSlider("myIntSlider", "This is my slider", 0, 3, 0, null, sliderValues);
}

Result
Float slider with range from 0 to 3 with default value as 0, and text values from sliderValues array
0 = "Something"
1 = "Something2"
2 = "Something3"
3 = "Something4"
obraz

SettingsTextBox

Use to add editable textbox to settings

AddTextBox(string settingID, string name, string value, string placeholderText, bool visibleByDefault = true) 
AddTextBox(string settingID, string name, string value, string placeholderText, InputField.ContentType contentType, bool visibleByDefault = true)

Note: second overload may require you to add UnityEngine.UI.dll reference
settingID - unique setting ID
name - Name of the textbox (visible in settings)
value - Default text value (type string.Empty if no default value needed)
placeholderText - placeholder text shown inside textbox when value is empty (like "enter text here...")
(Optional) contentType - Unity InputField.ContentType
(Optional) visibleByDefault - is setting visible by default

Usage Examples

SettingsTextBox my_textBox;

private void Mod_Settings()
{
    Settings.AddHeader("This is TextBox test");
    my_textBox = Settings.AddTextBox("my_textBox", "This is my TextBox", string.Empty, "Enter text here...");
}

Result
TextBox without default value with placeholder "Enter text here..."
obraz

SettingsCheckBox

Used to add checkBox to mod settings

AddCheckBox(string settingID, string name, bool value = false, Action onValueChanged = null, bool visibleByDefault = true)

settingID - unique setting ID
name - Name of the checkbox (visible in settings)
value - Default value (true or false)
(Optional) onValueChanged - Do something when value changed (set to null if not needed)
(Optional) visibleByDefault - is setting visible by default

Usage Examples

SettingsCheckBox my_checkBox;

private void Mod_Settings()
{
    Settings.AddHeader("This is CheckBox test");
    my_checkBox = Settings.AddCheckBox("my_checkBox", "This is my CheckBox", false);
}

Result
CheckBox named This is my CheckBox with default value false
obraz

SettingsDropDownList

Used to add DropDown List to mod settings

AddDropDownList(string settingID, string name, string[] arrayOfItems, int defaultSelected = 0, Action OnSelectionChanged = null, bool visibleByDefault = true)

settingID - unique setting ID
name - Name of the checkbox (visible in settings)
arrayOfItems - Array of names that will be displayed in DropDownList
(Optional) defaultSelected - Selected Index by default (0 if not set)
(Optional) OnSelectionChanged - Do something when value changed (set to null if not needed)
(Optional) visibleByDefault - is setting visible by default

Usage Examples

SettingsDropDownList dropDownList;

private void Mod_Settings()
{
    Settings.AddHeader("This is DropDownList Test");
    string[] ItemNames = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" };
    dropDownList = Settings.AddDropDownList("myList", "This is my DropDownList", ItemNames);
}

Result
DropDownList with default selected item as 0.
obraz
obraz

SettingsColorPicker

Used to add Color Picker (RGB or RGBA) to mod settings

AddColorPickerRGB(string settingID, string name, Action OnColorChanged = null, bool visibleByDefault = true) 
AddColorPickerRGBA(string settingID, string name, Action OnColorChanged = null, bool visibleByDefault = true) 
AddColorPickerRGB(string settingID, string name, Color32 defaultColor, Action OnColorChanged = null, bool visibleByDefault = true)
AddColorPickerRGBA(string settingID, string name, Color32 defaultColor, Action OnColorChanged = null, bool visibleByDefault = true) 

settingID - unique setting ID
name - Name of the color picker (visible in settings)
(Optional) defaultColor - Default color (0,0,0,255 [black] if not set)
(Optional) **OnColorChanged ** - Do something when color changed (set to null if not needed)
(Optional) visibleByDefault - is setting visible by default

Usage Examples

This example shows both Color pickers (with alpha and without)

SettingsColorPicker colorPicker, colorPickerA;

private void Mod_Settings()
{
    Settings.AddHeader("This is Color Picker Test RGB");
    colorPicker = Settings.AddColorPickerRGB("colorPicker", "This is my color picker", () => ModConsole.Print($"Selected color: {colorPicker.GetValue()}"));
           
    Settings.AddHeader(this, "This is Color Picker Test RGBA");
    colorPickerA = Settings.AddColorPickerRGBA("colorPicker2", "This is my color picker", () => ModConsole.Print($"Selected color: {colorPickerA.GetValue()}"));

}

Result
RGB/RGBA color picker
obraz

Other Settings types

AddButton

AddButton(string name, Action onClick, bool visibleByDefault = true)
AddButton(string name, Action onClick, SettingsButton.ButtonIcon predefinedIcon, bool visibleByDefault = true)
AddButton(string name, Action onClick, Texture2D customIcon, bool visibleByDefault = true)
AddButton(string name, Action onClick, Color btnColor, Color buttonTextColor, bool visibleByDefault = true)
AddButton(string name, Action onClick, Color btnColor, Color buttonTextColor, SettingsButton.ButtonIcon predefinedIcon, bool visibleByDefault = true)
AddButton(string name, Action onClick, Color btnColor, Color buttonTextColor, Texture2D customIcon, bool visibleByDefault = true)

name - Name of the Button
onClick - Function to execute when button is clicked
(Optional) predefinedIcon - Add icon from T_MSCLoader_SettingsButton_ButtonIcon
(Optional) customIcon - Custom Texture2D as icon
(Optional) btnColor - Background button color (Default new Color32(85, 38, 0, 255))
(Optional) buttonTextColor - Text Color (Default Color.white)
(Optional) visibleByDefault - is setting visible by default

Usage Examples

private void Mod_Settings()
{
    Settings.AddHeader("This is Button test");
    Settings.AddButton"my_button", "This is My Button", DoSomethingCool);
}

private void DoSomethingCool()
{
    ModUI.ShowMessage("You clicked this button", "It works!");
}

AddHeader

Adds a collapsable Header

AddHeader(string HeaderTitle, bool collapsedByDefault = false, bool visibleByDefault = true)
AddHeader(string HeaderTitle, Color backgroundColor, bool collapsedByDefault = false, bool visibleByDefault = true)
AddHeader(string HeaderTitle, Color backgroundColor, Color textColor, bool collapsedByDefault = false, bool visibleByDefault = true)

HeaderTitle - Title of your header
(Optional) backgroundColor - Background color of header (Default new Color32(95, 34, 18, 255))
(Optional) textColor - Text Color of header (Default new Color32(236, 229, 2, 255))
(Optional) collapsedByDefault - Is header collapsed by default
(Optional) visibleByDefault - is visible by default

AddText

Add just a text (It supports unity rich text tags)

AddText(string text, bool visibleByDefault = true)

text - text (supports unity rich text tags)
(Optional) visibleByDefault - is visible by default

Usage Examples

private void Mod_Settings()
{
    Settings.AddHeader("This is Text test");
    Settings.AddText("This is text, can be any lenght, and supports unity <color=aqua>Rich text tags</color>");
}
⚠️ **GitHub.com Fallback** ⚠️