BGP+ MenuAPI
A downloadable game
I've decided that the game won't use a custom package for mods, just Bepinex. Heres the menu API to add custom buttons for your mods.
MENU API – USAGE GUIDE ======================
- INTRODUCTION
This Menu API allows you to create custom UI buttons inside the "Title" scene of a Unity game. It works by locating the existing "Settings" button and using it as a prefab template. Other DLLs can call the API to create new buttons with custom text and custom logic.
Files included in the DLL:
- MenuAPI.cs
- CustomButtonLogic.cs
The API automatically activates when the "Title" scene loads.
- HOW THE API WORKS
When the game loads the "Title" scene, the API searches for a GameObject named "Settings". This must be a Unity UI Button. Once found, the API stores it internally as a prefab reference.
Other scripts can then call MenuAPI.CreateButton() to generate new buttons.
- CREATING A NEW BUTTON
To create a new button, call:
MenuAPI.CreateButton(position, text);
Where:
- position = Vector2 anchored position relative to the canvas
- text = the TMP label that will appear on the button
Example: MenuAPI.CreateButton(new Vector2(0, -200), "Mods");
This will:
- Clone the Settings button
- Move it to the given position
- Change the TMP text
- Remove all existing script components
- Add CustomButtonLogic.cs to the new button
- ACCESSING THE CUSTOM SCRIPT
Every button created by the API automatically receives a CustomButtonLogic component.
Example usage:
var btn = MenuAPI.CreateButton(new Vector2(0, -200), "Mods"); var logic = btn.GetComponent<CustomButtonLogic>(); logic.DoSomething();
The DoSomething() function is just an example. You can expand CustomButtonLogic.cs with your own features.
- REQUIREMENTS
- The "Title" scene must contain a UI Button named "Settings".
- The button must have a TMP_Text child.
- The MenuAPI.cs script must be loaded before or during the Title scene.
- The DLL must be placed in the game’s managed folder or loaded by your mod loader.
- TROUBLESHOOTING
If the API prints: "[MenuAPI] Could not find 'Settings' button" then the button name is incorrect or not present in the scene.
If the TMP text does not change, ensure the button has a TextMeshPro component as a child.
If the button does not appear, check the canvas hierarchy and ensure the cloned button is not disabled.
- SUMMARY
- The API hooks into the Title scene
- Finds the Settings button
- Lets you clone it
- Lets you set custom text
- Removes old scripts
- Adds your own custom logic
This provides a clean, reusable way for multiple DLLs to add menu entries without conflicts.
| Status | Released |
| Author | RomanGuy-Games |
Leave a comment
Log in with itch.io to leave a comment.