Next: , Previous: , Up: Inventory   [Contents][Index]


10.6 Inventory

Component: Inventory

Does not use object pooling. This component implements a locally-saved single-player only inventory for player items. It’s static, meaning there can only be one at any given time, or weird stuff might happen (probably not, but no guarantees). Each inventory item needs 2 prefabs: an ’ActiveItem’ which represents the object while it’s in-use, as well as a ’Pickable’ which represents the item when it’s on the ground. These need to have references to each other in the inspector and they all need to be in a’Resources’ folder or you might get errors when saving & loading.

Inventory Settings

Field of Inventory: int inventorySize

Max items in inventory

Default value: 10

Input Settings

Field of Inventory: bool controlCursorState

Should we lock the cursor when closing the inventory, and unlock it when opening the inventory?

Default value: false

Field of Inventory: KeyCode inventoryKey

Key allowing the player to open/close the inventory GUI

Default value: KeyCode.I

Field of Inventory: bool allowNumberKeys

Can the first items be accessed using number keys? This iterates through the inventory in-order looking for anything that is set to ’Weapon R’ mount (right-handed weapon).

Default value: true

Field of Inventory: float weaponSwapSensitivity

How sensitive is the mouse wheel when switching weapons?

Default value: 0.025f

GUI Settings

Field of Inventory: bool showInventoryGUI

Should we show the GUI displaying the inventory contents?

Default value: false

Field of Inventory: bool useHandButtons

Should we use buttons to drop/stow items held in the hand?

Default value: true

Field of Inventory: Rect inventoryArea

Normalized viewport rectangle indicating the inventory GUI area

Default value: new Rect(.2f,.2f,.6f,.6f)

Field of Inventory: int numButtonsPerRow

How many buttons can we have in a row?

Default value: 4

Field of Inventory: int numButtonsPerColumn

How many buttons can we have in a column?

Default value: 4

Available Messages

Message on Inventory: Save ()

Saves the inventory in a binary file on the player’s machine. Does not work on web builds

Message on Inventory: Load ()

Loads inventory from a binary file on the player’s machine. Does not work on web builds

Message on Inventory: Remove (string)

Allows you to remove an item from the player’s inventory by passing it’s inventory key

Argument: The inventory key of the item you want to remove

Message on Inventory: NextWeapon (bool)

Searches the inventory for the next Active Object with ’Item Type’ of ’WeaponR’ and equips it

Argument: Should we reverse the operation (previous weapon)?

Inventory Settings

Field of Inventory: int inventorySize

Max items in inventory

Default value: 10

Input Settings

Field of Inventory: bool controlCursorState

Should we lock the cursor when closing the inventory, and unlock it when opening the inventory?

Default value: false

Field of Inventory: KeyCode inventoryKey

Key allowing the player to open/close the inventory GUI

Default value: KeyCode.I

Field of Inventory: bool allowNumberKeys

Can the first items be accessed using number keys? This iterates through the inventory in-order looking for anything that is set to ’Weapon R’ mount (right-handed weapon).

Default value: true

Field of Inventory: float weaponSwapSensitivity

How sensitive is the mouse wheel when switching weapons?

Default value: 0.025f

GUI Settings

Field of Inventory: bool showInventoryGUI

Should we show the GUI displaying the inventory contents?

Default value: false

Field of Inventory: bool useHandButtons

Should we use buttons to drop/stow items held in the hand?

Default value: true

Field of Inventory: Rect inventoryArea

Normalized viewport rectangle indicating the inventory GUI area

Default value: new Rect(.2f,.2f,.6f,.6f)

Field of Inventory: int numButtonsPerRow

How many buttons can we have in a row?

Default value: 4

Field of Inventory: int numButtonsPerColumn

How many buttons can we have in a column?

Default value: 4

Available Messages

Message on Inventory: Save ()

Saves the inventory in a binary file on the player’s machine. Does not work on web builds

Message on Inventory: Load ()

Loads inventory from a binary file on the player’s machine. Does not work on web builds

Message on Inventory: Remove (string)

Allows you to remove an item from the player’s inventory by passing it’s inventory key

Argument: The inventory key of the item you want to remove

Message on Inventory: NextWeapon (bool)

Searches the inventory for the next Active Object with ’Item Type’ of ’WeaponR’ and equips it

Argument: Should we reverse the operation (previous weapon)?


Next: , Previous: , Up: Inventory   [Contents][Index]