Class Wallet
Static helper class for dealing with the Wallet inventory.
Many methods are simply shortcuts for 'InventoryManager.wallet.xxx'.
Inheritance
Namespace: UnityEngine.GameFoundation
Syntax
public static class Wallet
Properties
definition
The InventoryDefinition of this Wallet. Determines the default InventoryItems and quantities.
Declaration
public static InventoryDefinition definition { get; }
Property Value
Type | Description |
---|---|
InventoryDefinition | The InventoryDefinition of this Wallet. |
definitionHash
Helper property for easily accessing the Wallet's InventoryDefinition Hash.
Declaration
public static int definitionHash { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The Wallet's InventoryDefinition Hash. |
definitionId
Helper property for easily accessing the Id of the Wallet's InventoryDefinition.
Declaration
public static string definitionId { get; }
Property Value
Type | Description |
---|---|
System.String | The Id of the Wallet's InventoryDefinition |
onItemAdded
This is a callback that will be invoked whenever an InventoryItem is added to the Wallet.
Declaration
public static BaseCollection<InventoryDefinition, Inventory, InventoryItemDefinition, InventoryItem>.BaseCollectionItemEvent onItemAdded { get; set; }
Property Value
Type | Description |
---|---|
UnityEngine.GameFoundation.BaseCollection.BaseCollectionItemEvent<> | A CollectionItemEvent fired whenever an InventoryItem is added to the Wallet. |
onItemQuantityChanged
Callback for when an InventoryItem quantity has changed.
Declaration
public static BaseCollection<InventoryDefinition, Inventory, InventoryItemDefinition, InventoryItem>.BaseCollectionItemEvent onItemQuantityChanged { get; set; }
Property Value
Type | Description |
---|---|
UnityEngine.GameFoundation.BaseCollection.BaseCollectionItemEvent<> | A CollectionItemEvent fired when an InventoryItem quantity has changed. |
onItemQuantityOverflow
Callback for when an InventoryItem quantity has gone above its minimum.
Declaration
public static BaseCollection<InventoryDefinition, Inventory, InventoryItemDefinition, InventoryItem>.BaseCollectionItemEvent onItemQuantityOverflow { get; set; }
Property Value
Type | Description |
---|---|
UnityEngine.GameFoundation.BaseCollection.BaseCollectionItemEvent<> | The CollectionItemEvent fired when an InventoryItem quantity has gone above its minimum. |
onItemRemoved
This is a callback that will be invoked whenever an InventoryItem is removed from the Wallet.
Declaration
public static BaseCollection<InventoryDefinition, Inventory, InventoryItemDefinition, InventoryItem>.BaseCollectionItemEvent onItemRemoved { get; set; }
Property Value
Type | Description |
---|---|
UnityEngine.GameFoundation.BaseCollection.BaseCollectionItemEvent<> | A CollectionItemEvent fired whenever an InventoryItem is removed from the Wallet. |
Methods
AddItem(Int32, Int32)
Adds more of the specified InventoryItemDefinition by Hash. Returns the new (or existing) InventoryItem. Returns the new InventoryItem when the InventoryItem didn't already exist in the Wallet and returns an existing reference when to the InventoryItem when the InventoryItem was already in the Wallet.
Declaration
public static InventoryItem AddItem(int itemDefinitionHash, int quantity = 1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | itemDefinitionHash | The Hash of the InventoryItemDefinition we are adding. |
System.Int32 | quantity | How many of this InventoryItem we are adding. |
Returns
Type | Description |
---|---|
InventoryItem | The InventoryItem that was added. |
AddItem(String, Int32)
Adds a new entry of the specified InventoryItemDefinition by Id. Returns the new or existing InventoryItem. Returns the new InventoryItem when the InventoryItem didn't already exist in the Wallet and returns an existing InventoryItem when the InventoryItem was already in the Wallet.
Declaration
public static InventoryItem AddItem(string itemdefinitionId, int quantity = 1)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemdefinitionId | The Id of the InventoryItemDefinition we are adding. |
System.Int32 | quantity | How many of this InventoryItem we are adding. |
Returns
Type | Description |
---|---|
InventoryItem | The new InventoryItem that was added, or null if Id is invalid. |
AddItem(InventoryItemDefinition, Int32)
Adds more of the specified InventoryItemDefinition. Returns the new (or existing) InventoryItem. Returns the new InventoryItem when the InventoryItem didn't already exist in the Wallet and returns an existing reference when to the InventoryItem when the InventoryItem was already in the Wallet.
Declaration
public static InventoryItem AddItem(InventoryItemDefinition itemDefinition, int quantity = 1)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | itemDefinition | The InventoryItemDefinition we are adding. |
System.Int32 | quantity | How many of this InventoryItem we are adding. |
Returns
Type | Description |
---|---|
InventoryItem | The InventoryItem that was added. |
ContainsItem(Int32)
Returns whether or not an InventoryItem exists within the Wallet.
Declaration
public static bool ContainsItem(int itemDefinitionHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | itemDefinitionHash | The Hash of the InventoryItemDefinition we are checking for. |
Returns
Type | Description |
---|---|
System.Boolean | True/False whether or not the InventoryItem is within the Wallet. |
ContainsItem(String)
Returns whether or not an InventoryItem exists within the Wallet.
Declaration
public static bool ContainsItem(string itemDefinitionId)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemDefinitionId | The Id of the InventoryItemDefinition to find. |
Returns
Type | Description |
---|---|
System.Boolean | True/False whether or not the InventoryItem is within the Wallet. |
ContainsItem(InventoryItemDefinition)
Returns whether or not an InventoryItem exists within the Wallet for specified InventoryItemDefinition.
Declaration
public static bool ContainsItem(InventoryItemDefinition itemDefinition)
Parameters
Type | Name | Description |
---|---|---|
InventoryItemDefinition | itemDefinition | The InventoryItemDefinition to find. |
Returns
Type | Description |
---|---|
System.Boolean | True/False whether or not the InventoryItem is within the Wallet. |
GetItem(Int32)
Gets an InventoryItem by InventoryItemDefinition Hash if it is contained within, otherwise returns null.
Declaration
public static InventoryItem GetItem(int itemDefinitionHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | itemDefinitionHash | The InventoryItemDefinition Hash of the InventoryItem to find. |
Returns
Type | Description |
---|---|
InventoryItem | The InventoryItem or null if not found. |
GetItem(String)
Gets an InventoryItem by InventoryItemDefinition reference if it is contained within, otherwise returns null.
Declaration
public static InventoryItem GetItem(string itemDefinitionId)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemDefinitionId | The Id of the InventoryItem to find. |
Returns
Type | Description |
---|---|
InventoryItem | The InventoryItem or null if not found. |
GetItems()
Returns an array of all items within the wallet.
Declaration
public static InventoryItem[] GetItems()
Returns
Type | Description |
---|---|
InventoryItem[] | An array of all items within the wallet. |
GetItems(List<InventoryItem>)
Fills the given list with all items found in the wallet.
Declaration
public static void GetItems(List<InventoryItem> inventoryItems)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<InventoryItem> | inventoryItems | The list to fill up. |
GetItemsByCategory(Int32)
This will return an array of all InventoryItems that have the given Category by CategoryDefinition id hash.
Declaration
public static InventoryItem[] GetItemsByCategory(int categoryHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | categoryHash | The id hash of the CategoryDefinition to check. |
Returns
Type | Description |
---|---|
InventoryItem[] | An array of the InventoryItems that have the given Category. |
GetItemsByCategory(Int32, List<InventoryItem>)
Fills the given list with items with the given category hash.
Declaration
public static void GetItemsByCategory(int categoryHash, List<InventoryItem> inventoryItems)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | categoryHash | The id hash of the CategoryDefinition to check. |
System.Collections.Generic.List<InventoryItem> | inventoryItems | The list to fill up. |
GetItemsByCategory(String)
Returns all an array of items in the wallet with the given category id.
Declaration
public static InventoryItem[] GetItemsByCategory(string categoryId)
Parameters
Type | Name | Description |
---|---|---|
System.String | categoryId | The category id to check. |
Returns
Type | Description |
---|---|
InventoryItem[] | An array of items in the wallet with the given category id. |
GetItemsByCategory(String, List<InventoryItem>)
Fills the given list with items with the given category id.
Declaration
public static void GetItemsByCategory(string categoryId, List<InventoryItem> inventoryItems)
Parameters
Type | Name | Description |
---|---|---|
System.String | categoryId | The category id to check. |
System.Collections.Generic.List<InventoryItem> | inventoryItems | The list to fill up. |
GetItemsByCategory(CategoryDefinition)
This will return all InventoryItems that have the given Category through an array.
Declaration
public static InventoryItem[] GetItemsByCategory(CategoryDefinition categoryDefinition)
Parameters
Type | Name | Description |
---|---|---|
CategoryDefinition | categoryDefinition | The CategoryDefinition we are checking for. |
Returns
Type | Description |
---|---|
InventoryItem[] | An array of the InventoryItems that have the given Category. |
GetItemsByCategory(CategoryDefinition, List<InventoryItem>)
Fills the given list with items with the given category.
Declaration
public static void GetItemsByCategory(CategoryDefinition categoryDefinition, List<InventoryItem> inventoryItems)
Parameters
Type | Name | Description |
---|---|---|
CategoryDefinition | categoryDefinition | The category to check. |
System.Collections.Generic.List<InventoryItem> | inventoryItems | The list to fill up. |
GetQuantity(Int32)
Gets the Quantity of an InventoryItem by its InventoryItemDefinition hash
Declaration
public static int GetQuantity(int inventoryItemDefinitionHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | inventoryItemDefinitionHash | InventoryItemDefinition hash of the item's quantity to get |
Returns
Type | Description |
---|---|
System.Int32 | Quantity of the requested Inventory Item. |
Exceptions
Type | Condition |
---|---|
System.Collections.Generic.KeyNotFoundException | The hash provided doesn't correspond to a valid item |
GetQuantity(String)
Gets the Quantity of an InventoryItem by its InventoryItemDefinition id
Declaration
public static int GetQuantity(string inventoryItemDefinitionId)
Parameters
Type | Name | Description |
---|---|---|
System.String | inventoryItemDefinitionId | InventoryItemDefinition id of the item's quantity to get |
Returns
Type | Description |
---|---|
System.Int32 | Quantity of the requested Inventory Item. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The parameter id is null or empty |
GetQuantity(InventoryItem)
Gets the Quantity of an InventoryItem by its reference
Declaration
public static int GetQuantity(InventoryItem inventoryItem)
Parameters
Type | Name | Description |
---|---|---|
InventoryItem | inventoryItem | InventoryItem reference of the item's quantity to get |
Returns
Type | Description |
---|---|
System.Int32 | Quantity of the requested Inventory Item. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The parameter id is null |
RemoveAll()
Removes all InventoryItems from the Wallet.
Declaration
public static void RemoveAll()
RemoveItem(Int32)
Removes an entry of the specified InventoryItemefinition by Hash.
Declaration
public static void RemoveItem(int itemDefinitionHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | itemDefinitionHash | The Hash of the InventoryItemDefinition to remove. |
RemoveItem(String)
Removes an entry of the specified InventoryItem by InventoryItemDefintion id.
Declaration
public static void RemoveItem(string itemDefinitionId)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemDefinitionId | The Id of the InventoryItemDefinition we are removing. |
RemoveItemsByCategory(Int32)
This will remove all InventoryItems that have the given Category by CategoryDefinition Hash.
Declaration
public static void RemoveItemsByCategory(int categoryHash)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | categoryHash | The Hash of the CategoryDefinition to remove. |
RemoveItemsByCategory(String)
This will remove all InventoryItems that have the given Category by CategoryDefinition Id.
Declaration
public static void RemoveItemsByCategory(string categoryId)
Parameters
Type | Name | Description |
---|---|---|
System.String | categoryId | The Id of the CategoryDefinition we are checking for. |
RemoveItemsByCategory(CategoryDefinition)
This will remove all InventoryItems that have the given Category.
Declaration
public static void RemoveItemsByCategory(CategoryDefinition category)
Parameters
Type | Name | Description |
---|---|---|
CategoryDefinition | category | The CategoryDefinition to remove. |
Reset()
Resets the contents of the Wallet.
Declaration
public static void Reset()
SetQuantity(Int32, Int32)
Sets the quantity of the InventoryItem within this Wallet of the specified InventoryItemDefinition by Hash
Declaration
public static void SetQuantity(int itemDefinitionHash, int quantity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | itemDefinitionHash | The Hash of the InventoryItemDefinition to set quantity for. |
System.Int32 | quantity | The new quantity value to set. |
SetQuantity(String, Int32)
Sets the quantity of an InventoryItem by InventoryItemDefinition Id.
Declaration
public static void SetQuantity(string itemDefinitionId, int quantity)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemDefinitionId | The Id of the InventoryItemDefinition we are checking for. |
System.Int32 | quantity | The new value we are setting. |
SetQuantity(InventoryItem, Int32)
Sets the quantity of an InventoryItem.
Declaration
public static void SetQuantity(InventoryItem item, int quantity)
Parameters
Type | Name | Description |
---|---|---|
InventoryItem | item | The InventoryItem to set quantity for. |
System.Int32 | quantity | The new quantity value to set. |