Inventory
Last updated
Last updated
Open or create a new Inventory Database asset. In the desired folder, right-click and select Create -> UHFPS -> Game -> Inventory Database.
To open the Inventory Builder window, double-click the asset or click the Open Inventory Builder button.
In the Inventory Builder window, click on the plus (+) button located on the left side near the Inventory Items label to add a new section.
To add a new item, right-click on the section and select Add Item.
In order to select an item icon, you need to click on the Select button, which will open up the sprite selection window. It is important to ensure that the Texture Type item icon is set to Sprite (2D and UI), otherwise you won't be able to find the icon.
Define the amount of space that an item will take up in the inventory by adjusting the Width and Height slider in the Item Grid View.
If the height of the image is greater than the width, you can invert the orientation of the image so that the icon will fit the entire space it occupies in the inventory.
If you have created a new Inventory Database, assign it to the Inventory component located in the GAMEMANAGER object.
To pickup your newly created item to the in-game inventory, change the layer of the object to Interact and add the Interactable Item component to it. Then, change the Interactable Type to Inventory Item and assign the pickup item with your item.
The list of items is automatically generated from the Inventory Asset reference from the Inventory component. Therefore, it is necessary to have the Inventory component added to the scene and to have the Inventory Asset assigned.
You can use the item title as an interact or examine title by toggling Use Inventory Title or Use Examine Title in the Item Settings.
You can define Item Custom Data that can be used when using the item. To define the Item Custom Data, simply write whatever you want in JSON format.
To access the custom data, you just need to have a reference to an InventoryItem that represents the item in the inventory. To get that reference, call the GetInventoryItem function from the Inventory component.
Here's the code snippet for that:
You can also have nested JSON data that you can access using the JObject reference:
To change a JSON property value, use the JObject reference directly, but instead of casting the value to a type, simply set the value. After changing the values, use the Update() function to save the changes in the custom data.
To open the Inventory Item Selector, derive from the IInventorySelector interface and call the OpenItemSelector() function on the Inventory component.
Here's a code snippet to open the item selector:
In the OnInventoryItemSelect() function, you will have all the necessary references with selected item, so you can perform any desired actions with the item.
To check if an item is a specific item, use the ItemProperty or ItemGuid fields and check if the selected item GUID is equal to the item reference field.
To define an item as a combinable item, enable the Is Combinable toggle in the item settings.
Go to the Combine Settings and add new combinations.
To trigger the combine event on the player item after combining it with another item, enable the Event After Combine toggle.
The combine event will only trigger on the second item, so you have to make the combination for example from Battery -> Flashlight.
Also make sure that the second item (Flashlight) is Usable and the Usable Type is Player Item.
In the player item script that derives from the PlayerItemBehaviour, override the CanCombine() and OnItemCombine() functions.
To equip a player item that can only be combined, enable the Select After Combine toggle. After enabling this toggle, you can select the Result Player Item.
To mirror the combine settings with the combine item, click on the Mirror button. This will transfer the current combination settings to the second item.
You can also create craftable combinations. To enable crafting, just toggle the Is Crafting property. This allows you to set the required amount of the current and second item to craft the result item. The combination will work as normal, but combining items will only be enabled when the required quantities are met.