Box Setup (Chests, Bags, Other Inventories)

v4.0

The Inventory module assumes a "Player Inventory", which is always available, and an "Other Inventory", which is variable for any other object which contains an inventory. Examples would include boxes, chests, drawers, or anything else that has an inventory attached to it.

Check out the "Inventory Area" objects in the Party Based RPG demo game to see how we've set up a number of re-usable objects with different settings. You can use these, or copy them to make your own.

You can add your own UI, background, and other elements to make it "your own".

Scripting setup

Each object which has an inventory should contain some script that you create which references the Box Inventory Panel prefab you copied and customized in the steps above. In the example below, we will populate the public GameObject boxInventoryPrefab with this object.

Note that this script will need to be custom coded for your project, but you can utilize the examples here.

Your script should reference the PanelManager, which should be attached to an object in your scene. Here is one way to access it, at the top of the script.

using static InfinityPBR.Modules.Inventory.PanelManager;

In this code below, we will instantiate the panel, populate the spots and items, and display it.

public void OpenInventory()
{
    panelManager.SetOtherPanel(panelManager.CreatePanel(boxInventoryPrefab, items, spots));
    if (!panelManager.otherPanel)
        return;

    panelManager.panelParent.gameObject.SetActive(true);
    panelManager.SetupOtherPanel();
}

PanelManager will handle the rest for you.

BoxManager already has this set up for you. I suggest you consider using it, or stealing from it!

Last updated