ModSettingsMenu Class - PULSAR-Modders/pulsar-mod-loader GitHub Wiki

The ModSettingsMenu class is used to add pages to the F5 menu, utilizing the UnityEngine IMGUI module. IMGUIs (Immediate Mode Graphical User Interface) are ways to handle GUIs purely through code. It isn't convenient for complicated GUIs, but handles simple interfaces well enough.

To make use of this class, inherit from PulsarModLoader.CustomGUI.ModSettingsMenu and reference UnityEngine.IMGUIModule.dll. It is recommended to add a using directive to UnityEngine.GUILayout.

using static UnityEngine.GUILayout;
using PulsarModLoader.CustomGUI;

namespace MyNamespace
{
    class MyGUIClass : ModSettingsMenu
    {
        public override string Name()
        {
            //Page name.
            return "MyGUIClass";
        }

        public override void Draw()
        {
            //GUI Code...
        }

        public override void OnOpen()
        {
            //Code for menu open...
        }

        public override void OnClose()
        {
            //Code for menu close...
        }
    }
}

Returns page name for display in the F5 menu.

public override string Name()
{
    return "MyName";
}

Display for the GUI, runs once every frame while GUI is active. Basic controls can be viewed in the example below. For Unity documentation on usable methods, look here.

bool ToggleBool = false;
float SliderFloat = 0f;
string TexFieldString = "";

public override void Draw()
{
    Label("MyLabel");
    
    if(Button("ButtonName"))
    {
        //Button code...
    }
    
    //Keep an eye on how you're reading output from the controls below, as they set the values of their variables every frame.

    ToggleBool = Toggle(ToggleBool, "Checkbox Label");

    //float HorizontalSlider(float inFloat, minSlider, maxSlider)
    SliderFloat = HorizontalSlider(SliderFloat, 0f, 1f);

    TextFieldString = TextField(TextFieldString)
}

The OnClose() and OnOpen() methods are pretty simple, executing every time the window is opened or closed.

public override void OnOpen()
{
    //Opening code, could be used to instantiate data for display.
}

public override void OnClose()
{
    //Closing code, could be used to save temp values.
}