top of page

Inventory System

In this project I have developed an Inventory system that is easily adjustable (number of inventory slots, type of items, sprites, stack-ability etc.).

​

It is also more or less a self sustaining system where it can be easily interacted through the available functions and is robust to the point where it is bug free (Or at least I think it is).

​

The Inventory system can be split into 4 different parts. With one of them handling 60% of the system. 

​

The 4 parts are:

​

 - JSON Database

 - Inventory handler

 - Hotbar

 - Event Handlers

​

JSON Database

The JSON file is used to keep all the data for each individual items. This allows us to easily store huge amounts of data efficiently and allows us to access the data easily as well. 

​

This also allows us to go creative and be flexible with what data each object has as the data are all unique to each item. This then allows us to have things such as individual stack sizes and description without causing an issue to the system. We can also easily add on, change, or remove items from the data as long as the format is kept consistent.

​

​

​

Here you can see how JSON is used. 

​

As you can see each individual item stores up to 8 different lines of data that are needed to be used for this project. 

​

The 8 different lines are (variable types are in brackets):

- ID (int)

The ID is basically a numerical code that is assigned to each item. None of the items share the same ID as it is used to identify the objects separately. The system also makes use of ID heavily to get the data from the database. 

​

- Title (string)

The Title is the name of the object itself. This is used as a display for the tooltip.

​

- Value (int)

While value isn't used currently, the value data is present for future projects. It is used to signify the value of the object.

​

- Stackable (bool)

This allows the system to check if the object is able to stack.

​

- Stack Amount (int)

If the object is stackable, this is used to check how much the object can stack. This allows the system to know if the item is to be stacked with a stack in the inventory or is to make a new stack itself.

​

- Slug(string)

This is basically the same as a title but is changed to be more 'code friendly' by replacing capital letters with lower ones and replacing spaces with an underscore. This allows the system to look in the database through slug as well. 

​

- Description(string)

Used to be displayed in the tooltip.

​

- Rarity(int)

Used to change the colour of the title in the tooltip according to the rarity of the item

​

This database is then access and cached in a script present in the game. This way it improves performance as the game do not have to constantly read data from the JSON file while the game is running. 

Inventory handler

This handles the number of inventory slots and hotbar slots needed for the project. On top of that it handles the adding of objects into the inventory simply by the ID given to it.  

​

The inventory handler can be split into 3 parts.

 - Handling of Data

 - Handling of Visuals 

 - Adding of Objects

​

Handling of Data

The inventory helps to hold all the data in the inventory. This includes the number of slots, whats in each individual slots, and how many of the item is in a slot. This works together with the other parts and other scripts to keep the system robust and stable.

​

Handling of Visuals

The Inventory is also in-charge of making sure the right visuals to the player. This is because not all individual items have their own prefab, instead, they share the same prefab and stores the data on the prefab (which is stored in the inventory handler as well) Hence the visual side is also handled by the inventory handler as it helps assign the correct sprite and stack number to the objects. 

​

Adding of Objects
The adding of object works together with the database to allow the user to add object through the use of their item ID or slug. While theoretically you can also pull data for the item through description as well, we do not, as some items may have similar descriptions, however every item have a unique ID or Slug, 

​

The items are added safely and easily by checking with the data stored on the inventory handler. This prevents items being added into an inventory slot that already contain an item or making a new stack when the object can be stacked onto an existing stack. 

Hotbar

The hotbar is basically an easy access slot to items when the inventory is closed. 

 

It updates itself if an object is added into a hotbar slot or or the inventory panel is closed to match what is in the inventory hotbar slots both visually and in terms of data. 

 

The data in the slot is identical to the one in the inventory panel. This allows the panel to be easily modified and improved to allow usage of items in the slot.  

Event handlers

Event handlers were also used in this project. events such as on enter and drag were used to allow the use of tooltips for each items and also allow the user to drag the items to different slots. 

​

The event handlers helps to simplify the process as it can help store information such as the item data of the item it is dragging. 

© 2016 by Tomoaki Itabashi. Proudly created with Wix.com

  • LinkedIn Clean Grey
bottom of page