Class ItemList
Container for InventoryItem instances. Could be used for contents of a backpack, NPC inventory, etc.
Namespace: UnityEngine.GameFoundation
Syntax
public class ItemList : IItemCollection, ICollection<InventoryItem>, IEnumerable<InventoryItem>, IEnumerable
Properties
Count
Count of InventoryItems in this ItemList.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Implements
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList 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
IsReadOnly
Gets a value indicating whether this ItemList is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Item[Int32]
Retrieve InventoryItem by indexer.
Declaration
public InventoryItem this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | Index into ItemList to retrieve. |
Property Value
| Type | Description |
|---|---|
| InventoryItem | Specified InventoryItem. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
Methods
Add(IEnumerable<InventoryItem>)
Adds all InventoryItem in IEnumerable. Note: ItemList can only contain 1 copy of any item so any Add(InventoryItem) methods already contained in ItemList are ignored.
Declaration
public void Add(IEnumerable<InventoryItem> inventoryItems)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<InventoryItem> | inventoryItems | IEnumerable of all InventoryItems to add to this ItemList. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from th IInventoryManager. |
Add(InventoryItem)
Adds specified InventoryItem. Note: ItemList can only contain 1 copy of any item so subsequent Add(InventoryItem) calls are ignored.
Declaration
public void Add(InventoryItem inventoryItem)
Parameters
| Type | Name | Description |
|---|---|---|
| InventoryItem | inventoryItem | Item to add to this ItemList. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
AssertActive()
Throws a NullReferenceException if this ItemList is discarded.
Declaration
[ExcludeFromDocs]
protected void AssertActive()
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
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
CopyTo(InventoryItem[], Int32)
Copy the entire ItemList to a compatible one-dimensional Array, starting at the specified index of the target Array.
Declaration
public void CopyTo(InventoryItem[] array, int arrayIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| InventoryItem[] | array | The one-dimensional Arrayy that is the destination of the elements copied from thi ItemList. The Array must have zero-based indexing. |
| Int32 | arrayIndex | The zero-based index in Array at which copying begins. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
CreateItem(InventoryItemDefinition)
Helper method to create a new InventoryItem and automatically add it to this ItemList.
Declaration
public InventoryItem CreateItem(InventoryItemDefinition itemDefinition)
Parameters
| Type | Name | Description |
|---|---|---|
| InventoryItemDefinition | itemDefinition | InventoryItemDefinition to use to create InventoryItem. |
Returns
| Type | Description |
|---|---|
| InventoryItem | Newly-created InventoryItem in this ItemList. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
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<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<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<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, 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<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
GetEnumerator()
Get ItemList.Enumerator to facilitate iteration through this ItemList.
Declaration
public ItemList.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| ItemList.Enumerator | ItemList.Enumerator to permit iteration through this ItemList. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList 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
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
IndexOf(InventoryItem)
Find index of specified InventoryItem.
Declaration
public int IndexOf(InventoryItem inventoryItem)
Parameters
| Type | Name | Description |
|---|---|---|
| InventoryItem | inventoryItem | InventoryItem to find. |
Returns
| Type | Description |
|---|---|
| Int32 | Index of specified InventoryItem or -1 if not found. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |
Remove(Int32)
Remove specified ItemList item by index.
Declaration
public void Remove(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | Index to remove. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList 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
Swap(Int32, Int32)
Swap 2 items in the ItemList by index.
Declaration
public void Swap(int index0, int index1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index0 | Index of first InventoryItem to swap. |
| Int32 | index1 | Index of InventoryItem to swap with. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | If this ItemList is being used after it has already been removed from the IInventoryManager. |