Display Panel & Manager
Panels are used to be opened and closed. Each time a panel is open it can be given a reference to the panel that was previously opened such the previous panel may be selected once the current panel is closed. This allows total control on the order panels are opened and how it rolls back when closing panels. The display manager keeps track of all the panels and more.
Important: If your game already has a UI system, it is not required to use the Display Panel Manager and Display Panel. It may require some coding but the Inventory Grid, Item Hotbar, Item View, etc… can be used without Display Panels. If assistance is required checkout the forum.
Display Panel Manager
The purpose of the Display Panel Manager is to keep track of all the panels in it’s children. In the case of menus we restrict to being able to only open one menu at a time. You may chose to prevent opening a menu if one is already opened, or close the current menu when opening the new one. You may also chose to set the time scale to 0, otherwise it is recommend to listen to the “GameObject_OnPanelOpenClose_OpenClosePanelInfo” event to disable input for example.
The Display Panel Manager can be selected by ID from the Inventory System Manager.
The Panel Owner is very important. It is a GameObject that will receive events about panels closing, opening and more.
It is highly recommend (in some cases even necessary) to use the character game object (The game object with the Inventory, Item User, Inventory Input, etc… components) as Panel Owner.
Tip: Multiple display panel managers can be created for a split screen setup.
// Get the Display Panel Manager by ID from the Inventory System Manager singleton. var displayPanelManager = InventorySystemManager.GetDisplayPanelManager(ID); // Get the Panel Owner. It is a GameObject, usually the character GameObject with the Inventory component. // The panel owner also receives events about panels opening/closing and more. var panelOwner = displayPanelManager.PanelOwner; // Get a panel by the panel name. var panel = displayPanelManager.GetPanel(panelName); // Open a panel from the panel managers, this uses the current selected panel as the previous panel. displayPanelManager.OpenPanel(panel); // Get the selected panel. var selectedPanel = displayPanelManager.SelectedDisplayPanel; // Get the selected menu. var selectedMenu = displayPanelManager.SelectedDisplayMenu; // Close the selected panel. displayPanelManager.CloseSelectedPanel(); // Register to the event for opening/closing panels, (All events can be found in EventNames.cs)
EventHandler.UnregisterEvent<PanelEventData>(m_PanelOwner, EventNames.c_GameObject_OnPanelOpenClose_PanelEventData, PanelOpenedOrClosed);
A Selectable object must always be in focus in order to have proper keyboard or controller support. To assist with this the Prevent Selectable Deselection component will always select the previous selected Selectable if there is no selection.
Display Panel
Display Panels are used to open and close UI. There are a few options which allow to customize the functionality of the panel:
- Unique Name: This allows the Display Panel Manager to create a dictionary matching names to panels, allowing for easy access from anywhere in the code.
- Is Menu Panel: If true the panel will act as a menu, which means the Display Panel Manager will only allow one to be open at any one time.
- Is Non Selectable: This prevents the Display Panel Manger to register the panel as selected. It is particularly useful for tooltips as you may wish to open & close it without changing the chain of panels.
- Start Enabled: By default all panels start disabled, you may choose to start enabled.
- Open on Start: Similar to start enabled, except it will send a OnOpen event right at the start.
- Set Active On Open: Set the game object active on open.
- Set Disable On Close: Sets the game object inactive on close.
- Selectable On Open: Choose a selectable which will be selected once the panel is opened.
- Main Content: This is used extensively by UI Designer to know where prefabs should be spawned.
- Bindings: Bindings do not have to be set manually they are found on awake if they are set on the same game object. Panel Bindings get events for Open, Close, etc.
The interesting part with panels are the panel bindings, for example all Menus (Main Menu, Shop Menu, etc…) are all Panel Bindings. All they need to know is when to initialize, Open and Close. The most common examples of Display Panels & Binding set ups are:
Display Panel Menus, Example Main Menu
Item View Slots Container Panel Binding (For an Inventory Grid, Item Hotbar, Equipment Panel, etc.)
Tip: For Item View Slots Container Panel Binding you may choose to Bind To Panel Owner Inventory, this is very useful as you may set up the inventory to use in a single place.
// Open the panel using the Panel Manager which uses the currently selected panel. panel.SmartOpen(); panel.SmartClose(); // Get references to the objects and the state of the panel. DisplayPanel previousPanel = panel.PreviousePanel; Selectable previousSelectable = panel.PreviousSelectable; bool isOpen = panel.IsOpen; var panelManager = panel.Manager; string panelName = panel.UniqueName; List<DisplayPanelBinding> panelBindings = panel.Bindings; // Open the panel specifying the previous panel and selectable. panel.Open(previousPanel, previousSelectable) // Close the panel where the parameter selectPrevious is a bool which true will open the previous panel once this one is closed. panel.Close( true )