Add a Mods menu page
Add a page to the Mods menu (the “MODS” button on the main menu) with a title, a line of text and a button. Use it when your mod needs controls of its own that a plain setting cannot give.
ModMenu.AddPage registers the page. The method you give it builds the page when the player opens it, using ModUi helpers. ModUi draws with the game’s text and button types, so your project needs two more references first.
- Open your
.csprojfile in a text editor. Find the<ItemGroup>that holds the other<Reference>lines, and add these two references inside it, before its closing</ItemGroup>. They point at game files in theManagedfolder.Privateset tofalsekeeps the build from copying the game’s files into your output.
<Reference Include="Unity.TextMeshPro">
<HintPath>$(ManagedDir)\Unity.TextMeshPro.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(ManagedDir)\UnityEngine.UI.dll</HintPath>
<Private>false</Private>
</Reference>
- Replace the code in
Plugin.csof your project from Your first mod with this code.
using ObenseuerCore;
using ObenseuerCore.Ui;
using UnityEngine;
[ModInfo("example.menupage", "Menu Page", "0.1.0")]
[ModDependency("obenseuer.moddingframework", "0.11.0")]
public class MenuPage : FrameworkMod
{
protected override void OnLoad()
{
// Add a page: your mod id, the page title, and the method that builds the page.
ModMenu.AddPage("example.menupage", "Example Page", BuildPage);
}
// Runs when the player opens the page. "parent" is the empty page to fill.
private void BuildPage(RectTransform parent)
{
// A heading.
ModUi.Title(parent, "Example Page");
// A line of text. false means normal text, true would make it dim.
ModUi.Text(parent, "This page belongs to the example mod.", false);
// A button. Clicking it writes a line to this mod's log.
ModUi.Button(parent, "Log a click", ButtonStyle.Primary, () => Log.Info("menu page button clicked"));
}
}
- Run
dotnet build -c Release -p:DeployToGame=truewith the game closed, then start the game. Open the Mods menu and find Menu Page in the list. Click Log a click, then checkBepInEx\logs\example.menupage.login the game folder.
Pages added with ModMenu.AddPage are classic only. The build method runs in the classic uGUI window, whether the player opens the page from the classic sidebar or from the WebUi menu. The WebUi menu opens the classic pane for a page it does not render itself. A page never renders as HTML. Keep a classic page to labels, buttons and the ModUi kit. A mod that needs a rich control, such as a searchable dropdown, a colour picker or multi-line text, builds that in the WebUi menu instead. See the WebUi menu.
Notes:
ModMenu.AddPagetakes the mod id, the page title and a method that builds the page. The method runs when the player opens the page.- Other controls are in UI and HTML views and the UI reference.
- Config entries show up in the Mods menu on their own. A page is only needed for your own controls. See Config.
- The classic window is played with a controller as well as a mouse: the d-pad and the left stick move the focus, A or Enter activates the focused control, B or Esc goes back, and the bumpers switch sidebar pages. The footer shows the keys.
ModUicontrols are reachable this way; a rawSelectablethat the page builds itself is not.
Where to go next
Next: Add an HTML panel.