Character Item
CharacterItems are any object that the character can equip, such as an assault rifle, sword, bow, grenade, shield, flashlight, or book.
CharacterItems can be created on the character directly during edit time or can be prefabs that are dynamically added to the character at runtime. Read the Item Creation Guide for more information about the difference between the two.
In the hierarchy the CharacterItems will be placed as a child of the ItemPlacement component.
A CharacterItem is identified by its ItemIdentifier and its ItemDefinition. The ItemType is both an ItemDefinition and an ItemIdentifier.
The ItemIdentifier must be unique for each slot and is purely a representation of the CharacterItem GameObject that should be interacted with. ItemDefinitions allow you to easily reference which item should be picked up within the ItemPickup component, or which item should be used by the Use ability. Each item GameObject is required to have the CharacterItem component and this component implements the logic for more general item-related functions such as initialization, being picked up, equipped, dropped, etc.
Perspective Item
A Perspective Item represents the object that is actually rendered in the game. The Perspective Item class is an abstract class and is implemented by the First Person Perspective Item and the Third Person Perspective Item depending on which perspective is being rendered. The main responsibility of the perspective components are to spawn and to determine the location that the item should be rendered at. While both the first and third person components can use the spring system, the springs are more prevalent in a first person perspective because the component needs to handle bobs, sways, falls, etc. With a third person perspective the item is more restricted to the parent object (such as the hand).
The object that is actually held by the character and rendered on the screen is managed by the Item Perspective component. A First Person Item Perspective and a Third Person Item Perspective component should be added to the item GameObject depending on which perspective the item will be view with. The Item Perspective component is responsible for managing the item rendered to the screen.
At runtime the third person item hierarchy looks like:
The first person hierarchy is similar except under the character camera:
Item Action
When an ability is activated that performs an action on the item (such as a melee slash or grenade throw) it calls the corresponding ItemAction component to perform the actual action. Multiple ItemAction components can be added to the same item GameObject which will allow for the item to perform multiple functions. A classic example of this is an assault rifle that can shoot or be used as a blunt object with a melee attack. Another example could be a light sword attack or a heavy sword attack.
With all of these components added to the Item GameObject you’ll see a setup similar to the image below. In this image the item is setup for both a first and third person perspective, and it also can be used as a shootable weapon or a melee weapon.
API
Get the active CharacterItem from the Inventory:
CharacterItem characterItem = m_Inventory.GetActiveCharacterItem(slotID);
Get a CharacterItem by its ItemIdentifier from the Inventory:
CharacterItem characterItem = m_Inventory.GetCharacterItem(itemIdentifier, slotID);
Get all the CharacterItems in the Inventory:
ReadOnlyList<CharacterItem> characterItems = m_Inventory.GetAllCharacterItems();
Get the ItemIdentifier of a CharacterItem:
IItemIdentifier itemIdentifier = m_CharacterItem.ItemIdentifier;
Get the active Perspective Item of a CharacterItem:
PerspectiveItem perspectiveItem = m_CharacterItem.ActivePerspectiveItem;
Get the ItemActions of a CharacterItem:
CharacterItemAction[] itemActions = m_CharacterItem.ItemActions;
Check if the CharacterItem is active (meaning equipped):
bool isActive m_CharacterItem.IsActive();
Inspected Fields
Item Definition
A reference to the object used to identify the item.
Slot ID
Specifies the inventory slot/spawn location of the item.
Animator Item ID
Unique ID used for item identification within the animator.
Animator Movement Set ID
The movement set ID used for within the animator.
Dominant Item
Does the item control the movement and the UI shown?
Allow Camera Zoom
Can the camera zoom when the item is equipped?
Drop Prefab
The GameObject that can be dropped when the item is removed from the character.
Full Inventory Drop
When the item is dropped should the entire item be dropped? Throwable Items will want this option enabled.
Equip Event
Specifies if the item should wait for the OnAnimatorItemEquip animation event or wait for the specified duration before equipping. This field uses an Animation Event Trigger.
Equip Complete Event
Specifies if the item should wait for the OnAnimatorItemEquipComplete animation event or wait for the specified duration before stopping the equip ability. This field uses an Animation Event Trigger.
Equip Animator Audio State Set
Specifies the animator and audio state from an equip. This field uses an Animator Audio State Set.
Unequip Event
Specifies if the item should wait for the OnAnimatorItemUnequip animation event or wait for the specified duration before unequipping. This field uses an Animation Event Trigger.
Unequip Complete Event
Specifies if the item should wait for the OnAnimatorItemUnequipComplete animation event or wait for the specified duration before stopping the unequip ability. This field uses an Animation Event Trigger.
Unequip Animator Audio State Set
Specifies the animator and audio state from an unequip. This field uses an Animator Audio State Set.
UI Monitor ID
The ID of the UI Monitor that the item should use.
Icon
The sprite representing the icon.
Show Crosshairs On Aim
Should the crosshairs be shown when the item aims?
Center Crosshairs
The sprite used for the center crosshairs image.
Quadrant Offset
The offset of the quadrant crosshairs sprites.
Max Quadrant Spread
The max spread of the quadrant crosshairs sprites caused by a recoil or reload.
Quadrant Spread Damping
The amount of damping to apply to the spread offset.
Left Crosshairs
The sprite used for the left crosshairs image.
Top Crosshairs
The sprite used for the top crosshairs image.
Right Crosshairs
The sprite used for the right crosshairs image.
Bottom Crosshairs
The sprite used for the bottom crosshairs image.
Show Full Screen UI
Should the item’s full screen UI be shown?
Full Screen UIID
A unique ID for the UI in case multiple Full screen UI exist. -1 will use the first one found.
Events
Four Unity events are exposed by the item:
- Pickup Item
- Equip Item
- Unequip Item
- Drop Item
These events can be assigned within the item’s inspector.