Getting Started

This section shows how to work with the Item System. It has written and video tutorials, which helps you to get started.

Creating a Canvas
Create a new canvas inside Unity: Main Toolbar > GameObject > UI > Canvas
This will automatically create an Event System, that is required when working with UI.

Create an empty game object as a child of the canvas and setup the size. To create an empty game object, select the canvas in the Inspector > Context Click > Create Empty

Customize Visuals
Now you can customize the visuals of the inventory. For example you can create a background image as a child of the inventory game object.

Creating the Container
In the next step we need to attach the ItemContainer component to our inventory game object. Select the inventory game object and attach the ItemContainer component from the Main Toolbar > Tools > Item System > Components > ItemContainer

All ItemContainer components should have a unique name. We can now create a grid for the slots. Create a new game object as a child of the inventory and attach the GridLayoutGroup component to it through the Main Toolbar > Component > Layout > Grid Layout Group. The Cell Size is the size of your slots.

In the next step we can create the slots for our container. Create a Button through selecting the grid game object in the Inspector > Context Click > UI > Button and attach the ItemSlot component to the button through the Main Toolbar > Tools > Item System > Components > ItemSlot

You can now create optionally child components for the ItemSlot. The icon image will be set when an item is added to the slot, you can define the icon of the item in the Item Editor. The overlay field is a filled image, which will be updated with the cooldown progress. When creating the child components don’t forget to reference them in the ItemSlot.

Now that your slot is finished you can duplicate it to have multiple slots in the container.

To create  a new or update existing item open the Item Editor through the unity Main Toolbar > Tools > Item System > Editor
Click on the green Create button and select the item type that you would like to create.

In this tutorial i create a UsableItem, give it a name, description and other settings. When i drop the model into the prefab field a red button appears. This means that the prefab is not setup correctly, so just hit the setup button and the system will add all required components automatically. Furthermore it will ask you to save the prefab. The maximum stack of 0 means unlimited.

In the next step we add a behaviour to the item, when it is used. You can create custom behaviour actions extending from the BehaviourAction and overriding the Execute method. We add three actions to the conserv item.

  1. Cooldown: This action will cooldown the item and the container slots.
  2. Wait: Just delay the execution of actions.
  3. Remove: Remove the item from the container.

Now select the prefab that you saved in your project. In the inspector, you will see a component called ItemTrigger. This component handles the pickup of the item. You can see a list of items that will be added to the inventory, when a player pickups the item and also a list of containers where the item will be put in. When the system can’t add the item to the first container it will select and try the next in this list. This means you can have multiple inventory container windows.

Follow the instructions in 01. Creating Inventory to create an equipment ui container. Select a slot and drag and drop the EquipmentRegionValidation component. You can create new equipment regions inside the editor. This will make sure, that only items with this region are accepted inside the slot.

In the next step, drag and drop your player to the scene and attach the EquipmentHandler component from the Main Toolbar > Tools > Item System > Components > EquipmentHandler. Enter the equipment container name.

In the next step attach the item model to the bone, position it and drag and drop it to the Item Cache field and select the item identifying the attachement.

The example store/shop system is created using three containers.

1. Selection ItemContainer

Follow the instructions in 01. Creating Inventory to create a selection store container. Instead of duplicating the ItemSlots, disable the ItemSlot game object and tick the Dynamic Container field of your created store container. Drag and drop the grid transform and the disabled ItemSlot to the provided fields.

2. StoreContainer to buy items

Create an empty game object as child of the Canvas and change the visuals.

In the next step we create again a slot for the item. It should contain at least an icon(Image). Optionally we add a question text to it.

Create two buttons to increate/decrease the amount of items to buy and a text to display the current amount.

In the next step we create two more buttons. The first one to process the purchase and the second one to cancel and close the StoreContainer window. Furthermore we create a text component to display the current costs.

The visuals are now finished and we can continue to setup the container.

Attach the StoreContainer component to the Store Buy game object through Tools > Unitycoding > Item System > Components > StoreContainer or drag and drop the StoreContainer script to the game object.

Setup the StoreContainer component, giving it a name, drag and drop the slot icon, the amount text, the currency text(costs text), select the currency item from the item database(regular item).

All buttons should contain a Button component, where you can setup what happens on click. Drag and drop the StoreContainer game to the OnClick callback and choose the corresponding method.

Buy Button

Increase Button

3. StoreContainer to sell items

This container works the same way as described in 2. StoreContainer to buy items. So you can just duplicate the container(Store Buy) created in 2. and change the type to sell, update the visuals(Text) and the sell button choosing the StoreContainer.Sell method.

4. Setup StoreTrigger

To open the store window please see 05. Using Triggers.

Triggers are used to add items to containers.

1. ItemTrigger

The ItemTrigger can be used to pickup an item and put it into the players inventory. The order of the containers list sets the priority of storing the items. If the container with the highest priority is full, the ItemTrigger selects the next container in this list.

If the Generator Diffrence is greater then 0, the ItemTrigger will Randomize the properties of the item. within its range( Random.Range(propertyValue-generatorDiffrence,propertyValue+generatorDiffrence)). Currently it is possible only to randomize properties of type int and float.

2. ItemContainerTrigger

Similiar to the ItemTrigger, ItemContainerTrigger will add items to the ItemContainer. You have options to clear and sync the container. Forthermore the ItemContainerTrigger will open the container.

2. StoreTrigger

StoreTrigger extends from ItemContainerTrigger, but has options to modify the sell and buy price of items.




/// The item by region. ///Region. public EquipmentItem GetItemByRegion (EquipmentRegion region) { //Find the equipment container in scene ItemContainer window = UIUtility.Find (“Equipment”); //Get the slots from the window List<UISlot> slots=window.Slots; //Loop slots foreach(UISlot slot in slots){ //Check slot for EquipmentRegionValidation EquipmentRegionValidation validation=slot.GetComponent(typeof(EquipmentRegionValidation)) as EquipmentRegionValidation; if(validation != null && validation.region.Name==region.Name ){ //Return the item in the slot return slot.observedItem as EquipmentItem; } } //Return null if there is no slot with the given region. return null; } }