diablo style inventory

Hey guys,

Im currently working on an RPG like game and was wanting to implement a diablo style inventory, more specifically what im wanting is the way the items can take up more than one block and by rearranging your inventory you can make it hold more, so for example a potion would only take one block, but a weapon may be 2x6 blocks…

Any advice on how to handle the blocks and each item taking up different amount of inventory blocks would be great…

Im not asking for anyone to type the code, just how would I need to go about making this inventory…

Thanks in advanced!

Here’s how I’d do it:

Construct a 2D-array with the dimensions you want your inventory to be. The type of the array should be the base class that all items in your game inherit from. Here’s a snippet that does that, making the inventory 10x20 just for show:

ItemBaseClass[][] Inventory = new ItemBaseClass[10][];

for (int i = 0; i < Inventory.Length; i++)
{
    Inventory *= new ItemBaseClass[20];*

}
Think of that as a kind of table. Once you have that, you need to figure out how to easily convert adjacent cells in that table to indices in your 2D-array. This will enable you to highlight the adjacent cells that make up some sub-table of your 2D-array when the mouse hovers over some cell, i.e. when your mouse hovers over the cell at indices Inventory[0][0] and your mouse is dragging a 2x2 cells large item with it, your function needs to return cells (0,0), (1,0), (0,1) and (1,1), since those are the cells that are going to be filled with the object if you place it there.
Then, if the user clicks cell (0,0) to put the item there, you add references to that item to the 2D-array at all indices found to be covered by that item’s dimensions. So, whenever a user clicks to add some item, you simply have to make sure that all the indices in your array found to be needed by that placement point to null. If one or more of them don’t, it’s because some other item(s) occupy that cell.
Obviously, when the user picks up an item, you set the corresponding cells to null to indicate that that part of the inventory is now once more available.

There is a prefab for exactly what you want: #Unity3d - Adding an inventory to your game! - YouTube (This is the vid of the prefab beeing showcased) The down side is that you have o buy it.