Class ItemMap
Container for InventoryItems. Could be used for items attached to body parts, distributed around a room/dungeon, assigned to specific NPCs, etc.
Namespace: UnityEngine.GameFoundation
Syntax
public class ItemMap : IItemCollection, IEnumerable<InventoryItem>, IEnumerable
Properties
Count
Count of InventoryItems in this ItemMap.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Implements
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
hasBeenDiscarded
Determines if this IItemCollection has been discarded (removed from Game Foundation).
Items being standard objects, they cannot be destroyed and garbage collected as long as all their
references are not set to null
.
This property is a way for you to know if the object is still active within Game Foundation.
Declaration
public bool hasBeenDiscarded { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
Implements
id
Key used for this ItemList. Key is read-only and is set when created through IInventoryManager or will be assigned unique Guid.
Declaration
public string id { get; }
Property Value
Type | Description |
---|---|
String |
Implements
Item[String]
Gets or sets the value associated with the specified slot.
Declaration
public InventoryItem this[string slot] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
String | slot | The slot of the InventoryItem to get or set. |
Property Value
Type | Description |
---|---|
InventoryItem | InventoryItem associated with desired slot. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If slot or InventoryItem is |
InvalidOperationException | If item is added again with different slot. |
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
Methods
AssertActive()
Throws a NullReferenceException if this ItemMap is discarded.
Declaration
[ExcludeFromDocs]
protected void AssertActive()
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
ChangeSlot(String, String)
Change the slot for specified item in ItemMap.
Declaration
public bool ChangeSlot(string oldSlot, string newSlot)
Parameters
Type | Name | Description |
---|---|---|
String | oldSlot | |
String | newSlot |
Returns
Type | Description |
---|---|
Boolean | true if item was found and swapped, else false. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
ArgumentNullException | If either argument is null. |
Clear()
Remove all items from this IItemCollection.
Declaration
public void Clear()
Implements
Contains(InventoryItem)
Check if this ItemList contains specified InventoryItem.
Declaration
public bool Contains(InventoryItem inventoryItem)
Parameters
Type | Name | Description |
---|---|---|
InventoryItem | inventoryItem | InventoryItem for which to search. |
Returns
Type | Description |
---|---|
Boolean | true if specified InventoryItem is contained in this ItemList, else false. |
Implements
CreateItem(String, InventoryItemDefinition)
Helper method to create a new InventoryItem and automatically add it to this ItemMap.
Declaration
public InventoryItem CreateItem(string slot, InventoryItemDefinition itemDefinition)
Parameters
Type | Name | Description |
---|---|---|
String | slot | Slot to use when adding new InventoryItem to this ItemMap for later retrieval. |
InventoryItemDefinition | itemDefinition | InventoryItemDefinition to use to create InventoryItem. |
Returns
Type | Description |
---|---|
InventoryItem | Newly-created InventoryItem added to this ItemMap. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
Find(Func<String, InventoryItem, Boolean>)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Func<string, InventoryItem, bool> filter)
Parameters
Type | Name | Description |
---|---|---|
Func<String, InventoryItem, Boolean> | filter | The filter the InventoryItem instances have to fulfill. This filter takes the slot (String) and the InventoryItem instance, and it returns a Boolean if they meet its expectations. |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(Func<String, InventoryItem, Boolean>, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Func<string, InventoryItem, bool> filter, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<String, InventoryItem, Boolean> | filter | |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(Func<String, InventoryItem, Boolean>, ICollection<InventoryItem>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Func<string, InventoryItem, bool> filter, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<String, InventoryItem, Boolean> | filter | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(Predicate<InventoryItem>)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Predicate<InventoryItem> filter)
Parameters
Type | Name | Description |
---|---|---|
Predicate<InventoryItem> | filter | The filter the InventoryItem instances have to fulfill. |
Returns
Type | Description |
---|---|
Int32 | The number of items found. |
Implements
Find(Predicate<InventoryItem>, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Predicate<InventoryItem> filter, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Predicate<InventoryItem> | filter | The filter the InventoryItem instances have to fulfill. |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the (String slot, InventoryItem item) tuples are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(Predicate<InventoryItem>, ICollection<InventoryItem>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find(Predicate<InventoryItem> filter, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Predicate<InventoryItem> | filter | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found. |
Implements
Find(InventoryItemDefinition)
Finds the InventoryItem instances of the specified definition
.
Declaration
public int Find(InventoryItemDefinition definition)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | definition | InventoryItemDefinition to search for. |
Returns
Type | Description |
---|---|
Int32 | Count of InventoryItems with specified |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If |
Find(InventoryItemDefinition, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds all the InventoryItem instances of the specified definition
.
Declaration
public int Find(InventoryItemDefinition definition, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | definition | The InventoryItemDefinition filter. |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the (String slot, InventoryItem item) tuples are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(InventoryItemDefinition, ICollection<InventoryItem>, Boolean)
Finds the InventoryItem instances of the specified definition
.
Declaration
public int Find(InventoryItemDefinition definition, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | definition | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | Count of InventoryItems with specified |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If |
Find(Tag)
Finds the InventoryItem instances using specified Tag.
Declaration
public int Find(Tag tag)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | Tag to search for. |
Returns
Type | Description |
---|---|
Int32 | Count of InventoryItems with specified Tag. |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If |
Find(Tag, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds all the InventoryItem instances using the specified tag
.
Declaration
public int Find(Tag tag, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | The Tag filter. |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the (String slot, InventoryItem item) tuples are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found, with their related slot. |
Find(Tag, ICollection<InventoryItem>, Boolean)
Finds the InventoryItem instances using specified Tag.
Declaration
public int Find(Tag tag, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | Count of InventoryItems with specified Tag. |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If |
Find<TState>(Func<TState, String, InventoryItem, Boolean>, TState)
Finds the InventoryItem passing the filter.
Declaration
public int Find<TState>(Func<TState, string, InventoryItem, bool> filter, TState state)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, String, InventoryItem, Boolean> | filter | The filter the InventoryItem instances have to fulfill.
This filter takes the |
TState | state | The data used by the filter. |
Returns
Type | Description |
---|---|
Int32 | The number of InventoryItem found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Find<TState>(Func<TState, String, InventoryItem, Boolean>, TState, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds the InventoryItem passing the filter.
Declaration
public int Find<TState>(Func<TState, string, InventoryItem, bool> filter, TState state, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, String, InventoryItem, Boolean> | filter | |
TState | state | |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of InventoryItem found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Find<TState>(Func<TState, String, InventoryItem, Boolean>, TState, ICollection<InventoryItem>, Boolean)
Finds the InventoryItem passing the filter.
Declaration
public int Find<TState>(Func<TState, string, InventoryItem, bool> filter, TState state, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, String, InventoryItem, Boolean> | filter | |
TState | state | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of InventoryItem found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Find<TState>(Func<TState, InventoryItem, Boolean>, TState)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find<TState>(Func<TState, InventoryItem, bool> filter, TState state)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, InventoryItem, Boolean> | filter | The filter the InventoryItem instances have to fulfill. |
TState | state | The data used bny the filter. |
Returns
Type | Description |
---|---|
Int32 | The number of items found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Implements
Find<TState>(Func<TState, InventoryItem, Boolean>, TState, ICollection<(String slot, InventoryItem item)>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find<TState>(Func<TState, InventoryItem, bool> filter, TState state, ICollection<(string slot, InventoryItem item)> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, InventoryItem, Boolean> | filter | |
TState | state | |
ICollection<ValueTuple<String, InventoryItem>> | target | The target collection the (String slot, InventoryItem item) tuples are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Find<TState>(Func<TState, InventoryItem, Boolean>, TState, ICollection<InventoryItem>, Boolean)
Finds all the InventoryItem instances passing the filter
.
Declaration
public int Find<TState>(Func<TState, InventoryItem, bool> filter, TState state, ICollection<InventoryItem> target, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
Func<TState, InventoryItem, Boolean> | filter | |
TState | state | |
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | The number of items found. |
Type Parameters
Name | Description |
---|---|
TState | The type of the |
Implements
Get(String)
Find item associated with slot.
Declaration
public InventoryItem Get(string slot)
Parameters
Type | Name | Description |
---|---|---|
String | slot | Slot to find. |
Returns
Type | Description |
---|---|
InventoryItem | InventoryItem associated with slot or null if not found. |
GetEnumerator()
Get ItemMap.Enumerator to facilitate iteration through this ItemMap.
Declaration
public ItemMap.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
ItemMap.Enumerator | ItemMap.Enumerator to permit iteration through this ItemMap. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
GetItems(ICollection<InventoryItem>, Boolean)
Fill target
with all InventoryItems.
Declaration
public int GetItems(ICollection<InventoryItem> target = null, bool clearTarget = true)
Parameters
Type | Name | Description |
---|---|---|
ICollection<InventoryItem> | target | The target collection the InventoryItem instances are copied to. |
Boolean | clearTarget | If |
Returns
Type | Description |
---|---|
Int32 | Count of ItemLists owned by IInventoryManager. |
Implements
GetSlot(InventoryItem)
Finds slot (or null) for specified InventoryItem by reference.
Declaration
public string GetSlot(InventoryItem inventoryItem)
Parameters
Type | Name | Description |
---|---|---|
InventoryItem | inventoryItem | InventoryItem to find. |
Returns
Type | Description |
---|---|
String | Slot used for specified InventoryItem or null if not found. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
ArgumentNullException | If InventoryItem is |
GetTotalQuantity()
Count all InventoryItems in this IItemCollection (including total quantities of any StackableInventoryItems) and return total quantity.
Declaration
public long GetTotalQuantity()
Returns
Type | Description |
---|---|
Int64 | Total quantity of all items in IItemCollection. Non-stackable items count as 1, StackableInventoryItems count as the total stack quantity. |
Implements
GetTotalQuantity(InventoryItemDefinition)
Count all specified InventoryItemDefinition in this IItemCollection (including total quantities of any StackableInventoryItems) and return total quantity.
Declaration
public long GetTotalQuantity(InventoryItemDefinition definition)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | definition | InventoryItemDefinition to accumulate total quantity for. |
Returns
Type | Description |
---|---|
Int64 | Total quantity of all items. Non-stackable items count as 1, StackableInventoryItems count as the total stack quantity. |
Implements
IsSlotSet(String)
Check if specified slot is currently in this ItemMap.
Declaration
public bool IsSlotSet(string slot)
Parameters
Type | Name | Description |
---|---|---|
String | slot | Slot to search for. |
Returns
Type | Description |
---|---|
Boolean |
|
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
Remove(InventoryItem)
Remove specified ItemList item by reference.
Declaration
public bool Remove(InventoryItem inventoryItem)
Parameters
Type | Name | Description |
---|---|---|
InventoryItem | inventoryItem |
Returns
Type | Description |
---|---|
Boolean |
|
Implements
Remove(InventoryItemDefinition)
Remove all InventoryItems with specified InventoryItemDefinition.
Declaration
public bool Remove(InventoryItemDefinition definition)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | definition | InventoryItemDefinitions to find and remove. |
Returns
Type | Description |
---|---|
Boolean | true if any InventoryItemDefinitions were found and removed, else false. |
Implements
Set(String, InventoryItem)
Adds specified InventoryItem to this ItemMap using specified slot. Important: InventoryItems can only have ONE instance in the ItemMap and slot can only be Add-ed once. Please use Indexer to change value for a slot, or ChangeSlot(String, String) to change the slot for an InventoryItem.
Declaration
public void Set(string slot, InventoryItem inventoryItem)
Parameters
Type | Name | Description |
---|---|---|
String | slot | Slot to use for this InventoryItem. |
InventoryItem | inventoryItem | InventoryItem to add based on specified slot. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If item is added again with different slot. |
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
SwapSlots(String, String)
Swap 2 items in the ItemMap by slot string.
Declaration
public bool SwapSlots(string slot0, string slot1)
Parameters
Type | Name | Description |
---|---|---|
String | slot0 | Slot of item to swap. |
String | slot1 | Slot of item to swap with. |
Returns
Type | Description |
---|---|
Boolean |
|
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |
ArgumentNullException | If either argument is |
Unset(String)
Remove specified slot from this ItemMap.
Declaration
public bool Unset(string slot)
Parameters
Type | Name | Description |
---|---|---|
String | slot | Slot to remove. |
Returns
Type | Description |
---|---|
Boolean | true if slot was found and removed, else false. |
Exceptions
Type | Condition |
---|---|
NullReferenceException | If this ItemMap is being used after it has already been removed from the IInventoryManager. |