Item Objects

The Item Object component links a particular Item to the GameObject. Any item that is visible within the game world should have an Item Object component. For example, item pickups and equipped items are both ways that items can take shape in the game world.

The ItemObject component is quite flexible as it allows you to bind/unbind an item to it. Therefore you may easily pool some game objects with an ItemObject and reuse them to spawn any item in your scene.

An event is triggered when an item is attached or detached from an Item Object. Some components listen to that event to change how the ItemObject looks in the game world.

 

Item Object API

Register to the event
// Register to the event of the Item changing on the Item Object
EventHandler.RegisterEvent(m_ItemObject, EventNames.c_ItemObject_OnItemChanged, HandleItemChanged);

private void HandleItemChanged(){
	//The item changed
	var itemInfo = m_ItemObject.ItemInfo;
}
Attach an Item to an Item Object
// Set the item to the Item Object
var newItem = InventorySystemManager.CreateItem("MyItemName");

// By default it will add 1 unit of the item.
m_ItemObject.SetItem(newItem);

// You may change the amount at any time.
m_ItemObject.SetAmount(5);

// Alternatively you may set an Item Info.
var itemInfo = (ItemInfo)(5, newItem);
m_ItemObject.SetItem(itemInfo);
Get the Item Object from the Item
//If your Item is Unique you may get the Item Object from the Item
var itemObject = newItem.GetLastItemObject();

// You may easily check if an item is bound to an Item Object.
if(newItem.IsBoundToItemObject(itemObject)){
	//The item is bound to that item object.
}

// If it is not unique the item may have multiple Item Objects:
// Loop over all the item object
var count = newItem.GetItemObjectCount();
for(int i =0; i < count; i++){
	var itemObjectAtIndex = newItem.GetItemObjectAt(i);
}