OnScreenItem
v4.0
Last updated
v4.0
Last updated
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 class is attached to the Prefab Inventory Module Requires Scripts
. Bring that into your project.
This is a static method, which you can utilize via this code at the top of your script:
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.
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.
This is the UI parent for on screen held objects.
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.
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.
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.
These properties and variables provide more information about an item that is held -- or if one is being held at all.
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.
By default, the DropObject()
method will not drop a GameItemObject
which is marked as a questItem
. You can set ignoreQuestItems = true
to bypass this. Keep in mind, once it's thrown in the world, physics may make it go out of reach of the player!
The ignoreButtons
bool
is also false
by default. This means that if the mouse is over a UI button, the DropObject()
method will be ignored.
The player may have moused over a portrait of a character or other UI element that does something different when there is an item held.
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.
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.
If there is a physical object that needs to be turned off, don't forget to do so after Pickup()
returns true
!