MenuManager is a manager for menus inside UGUI.
With just a small amount of code you can create relations between different menus. Think of popups, tooltips but also any regular menu.
Clone the repository, use it as a git submodule or download a UnityPackage from the forums. Open te project in Unity. This repository contains all the code you want to include in your project under the 'Assets' folder.
This is the prefered way. Your current project will be your git repository and the MenuManager will be a submodule. This means it can be updated using git, but won't be in your way when managing your own repositories. To do this, go to the folder that contains all your packages (you can for example create a folder 'Imported' under 'Assets') and run the command git submodule add https://github.com/WeersProductions/MenuManager.git
in your git terminal. To update it, run git submodule update
.
In the Demo folder two demos show you how to use the MenuManager.
Demo | Shows |
---|---|
Popups | How to work with popups, tooltips and parent-child relations |
MultipleMenuControllers | How to use multiple menu controllers with shared menus |
- Create and/or open scene
- Open MenuManager editor (Window -> WeersProductions -> MenuManager)
- Press 'Create MenuController'
- Select an existing canvas of your scene, or press 'Create new'
- Select the newly created MenuController in the MenuManager editor on top
This system makes use of Unity Prefabs for different menus. Each menu (or popup/tooltip) is a prefab with a MCMenu
component (or a subclass), which is registered in the MenuController
class.
First you create your menu like you would usally do in the scene editor as a GameObject. This GameObject should have a MCMenu
component or a subclass.
To get started you can right click in the Hierarchy panel and click WeersProductions->Menu. This will create a new panel with the MCMenu
component.
Once you have finished your menu, make it prefab and delete the Scene instance. Drag your prefab to the 'Specific menus' drag area. This will add the new menu to the selected MenuController.
Since we need a reference to the menu in code, add your menu to the Menus
enum in the MenuController
file, with the value being the same as the ID
of the MCMenu
component.
public enum Menus
{
UNDEFINED = -2,
NONE = -1,
SIMPLEPOPUP = 0,
SIMPLETOOLTIP = 1
}
MenuController.ShowMenuGlobal(Menus.SIMPLETOOLTIP);
To show the new menu.
If you have, for example, a world canvas and a screen-space canvas, you might want to use two MenuControllers. This way they will keep track of their own states and pool their own menus.
In that case, calling ShowMenuGlobal
does not give enough information about what MenuController you are talking about.
Keep a reference to the MenuControllers and call
// Assign this sometime, E.G. in the editor.
MenuController _menuController;
// Call ShowMenu on the instance.
_menuController.ShowMenu(Menus.SIMPLETOOLTIP);
If you want a menu that should be possible to shown on every MenuController there is, without having to manually drag the prefab for each MenuController, use the 'Shared menus' drag area. These menus are added to all MenuControllers of your Unity project.
If your project contains a lot of menus, presets might help you organize them.
- Go to the tab
Create preset
, enter a name and clickCreate new
. Click on the new preset and set the description field. - Drag your menu prefab to the 'Preset Object' field at the bottom of the editor.
- Go to the tab
Create menu
, select your new preset and clickCreate Menu
. This will instantiate a new object for the current selected MenuController. Edit this, and follow 'Adding a new menu' to use it.
The main structure when looking at the data-flow when showing a new menu is as follows:
-
Create a new
data
object. This will contain data for the specific menu. Think of an object that contains the following properties:- Message
- Color of the message
- An icon that should be displayed next to the message
Example files:
-
This data will be send to your menu class, that inherits from
McMenu
. This class will use the data from the data object to show specific things on screen. In our example, think of a Message class that will set a UI Text component's text to the Message property, its color to the Color property and sets a UI Image component's Sprite property to the Icon that is sent.Example files:
You can see a very simple example in MainWindow of how to create a data object and use it when showing a menu.
Achieve interesting menu set-ups with very little code. Click on the demos to go to the demo readme with more explanation.
Multiple Managers | Popups |
If you have any questions of how to use this, or any suggestions on what features are missing, don't hesitate to send me a message!