PanelManager

v4.0

The PanelManager class manages the inventory panels during runtime. This is needed for games where there are up to two inventory panels active at once -- the player inventory panel, and potentially a "Other panel", which could be a treasure box or other object that has an inventory. This way, the user can easily navigate between the player inventory panel, the other panel, and transfer items back and forth.

This class is attached to the Prefab Inventory Module Requires Scripts. Bring that into your project.

This is a static method, which you can utilize via this code at the top of your script:

using static InfinityPBR.Modules.Inventory.PanelManager;

Required fields

Player Inventory Panel (Optional)

The module assumes that there will be an "always on" inventory panel for the player. While this is not static by any means, and can display the inventory of various players, such as in a game where there are multiple player members of a party, the inventory panel is assumed to not be destroyed or instantiated at run time.

While technically optional, we expect most projects will make use of this.

UI Camera [Hidden in Inspector]

This is the camera used to show the UI Inventory and canvas. This is set automatically by the PanelManager class.

Panel Parent

Inventory panels instantiated will be parented under this Rect Transform.

Show Debug Messages

When true, the Console will show Debug.Log messages during key events. This is helpful if you want to better understand which methods are being called during your interaction with the Inventory module. It will toggle off automatically when not in the Unity Editor.

Public methods

Get Active Panel

This will return whichever panel is active. It could be the player panel, or an "other" panel. Will return null if there is no active panel.

public Panel ActivePanel

Get Active Panel

This will return whichever panel is active. It could be the player panel, or an "other" panel. Will return null if there is no active panel.

public Panel ActivePanel

Set "Other" Panel

This will populate the otherPanel with the newPanel passed in, and optionally set the new panel to activate.

public Panel SetOtherPanel(Panel newPanel, GameObject obj, bool setActive = true)

Toggle Panels On/Off

Use these methods to set the Player panel and the Other panel active. The other will turn off at the same time.

iHaveInventoryGameId is the GameId of the object which will have its inventory displayed.

public void ToggleOtherInventoryPanel(bool turnOn = true)
public void TogglePlayerInventoryPanel(bool turnOn = true
    , string iHaveInventoryGameId = "")
    
// Example from Party Based RPG demo game calss GameData.cs
// OpenPlayerInventory()...
panelManager.TogglePlayerInventoryPanel(true, ActivePlayer.GameId());

Last updated