OnScreenItem

v4.0

The OnScreenItem class manages visual items that are "held" by the player between inventories. This is how a player may transfer items from one inventory to another, or even put the item into the 3D world.

This is a static method, which you can utilize via this code at the top of your script:

using static InfinityPBR.Modules.Inventory.OnScreenItem;
A populated OnScreenItem from the Party Based RPG demo game

Required fields

UICamera

This is the UI Camera which draws the UI and UI Inventory objects. The prefab is set up for you, and utilized in the demo scene. If you make changes, be sure to create your own original prefab first, so that you can reference the demo project later.

Player Transform

This is generally the transform of your player, and is used to instantiate UI Inventory objects into the 3D world, so a player can "drop" a held object into the world.

You are able to modify the code in order to instantiate the item in different locations, or have different logic than what is provided. For example, you may wish to allow a player to place a held object onto a specific location, rather than simply throwing it forward. For that functionality, some custom code would be required.

Held Object Parent Rect Transform

This is the UI parent for on screen held objects.

Z Position

This is the z position that UI Inventory objects will be instantiated at. Generally this can be left at default, though can be modified if needs be.

Drop Force

When the player "drops" the item into the world, some force is applied. You can modify the force here. You are also able to change the code itself to provide a different behavior when the object is dropped.

Public Properties & Variables

GameItemObject & GameObject

When an item is being held, there will be both a GameItemObject object, which holds all the data that makes up what the object is, and a GameObject, the physical object in the scene the player can see.

Item Details

These properties and variables provide more information about an item that is held -- or if one is being held at all.

Public methods

Drop Position Modifications

When the held item is "dropped", it will be put at the playerTransform.position + dropPositionModification + playerTransform.forward. Set this value of dropPositionModification in the Inspector.

When DropObject() is called, there are additional optional parameters to specify the position and "look at" another position. This is useful when you want the object to spawn elsewhere.

Give Held Object

You likely will not use this method!

This is called by the Panel class to pass a held item to a specific GameItemObjectList which is enabled with Spots, at a specific spotRow and spotColumn. While you generally will not be using this, it can be used if you have a reason to do so.

Pickup an object

This method will pickup an object, but will return false if the system is unable to.

First, if there is already a held item, the system will return false if it can't place the existing item into the AcitvePanel, or if there is no active panel available.

The method will also return false if there is no prefabInventory object on the gameItemObject being picked up.

After that, the item will be picked up. The new itemHeld will be a Clone() of the gameItemObject passed in.

Last updated

Was this helpful?