Use UI Components
Last updated
Last updated
It's pretty straightforward to work with the Inventory UI components. The demo example project provides prefab templates with working versions of typical gear, weapon and backpack inventories that are ready to go and network synced. There are also examples for typical things like chests that popup an inventory window.
The Net code is not in the UI space. The UI components just talk to the Inventory class that they are bound to and will send requests through it which simplifies the UI code quite a bit.
This component requires a GridLayoutGroup
to function. The restrictions are essentially Slot Types, or locks, where only items with corresponding restrictions or lock types can be slotted into this inventory. If there are no restrictions then it is ... well... unrestricted.
The array of restrictions will also operate as an index restriction for the Grid. This means that in the above example the first slot [0] on the grid will be restricted to Head armor, and so forth.
If you want the inventory to bind to the player then simply check the box and ensure that your Player code is doing something like this:
Note: If you have more than one local player, you'll have to start looking into how to support that as the built-in systems assume there is only one local player.
This is what is on every slot in the system. If you can put something there, it's an ItemUiPlug
. There's several references for updating the UI of Slots. If you examine the Template Slot prefab in the demo example then you can see how each part works. Really, you can override all of this and do whatever you want and just use the script for the interactive code bits.
If you're extending functionality to add more input support, context menus or other things that relate directly to the slots and their function then this is where you're looking.