docs.unity.cn
    Show / Hide Table of Contents

    Interface IInventoryManager

    Manages all InventoryItems and IItemCollections. Can subscribe to events relevant to InventoryItems and create and delete them here. The IInventoryManager can create InventoryItems from InventoryItemDefinitions as well as IItemCollections as needed.

    Namespace: UnityEngine.GameFoundation
    Syntax
    public interface IInventoryManager

    Methods

    CreateItem(InventoryItemDefinition)

    This will create a new InventoryItem based on the given InventoryItemDefinition.

    Declaration
    InventoryItem CreateItem(InventoryItemDefinition definition)
    Parameters
    Type Name Description
    InventoryItemDefinition definition

    The InventoryItemDefinition to assign to this Item.

    Returns
    Type Description
    InventoryItem

    The newly created item based on specified InventoryItemDefinition.

    CreateItem(StackableInventoryItemDefinition, Int64)

    This will create a new StackableInventoryItem based on the given StackableInventoryItemDefinition.

    Declaration
    StackableInventoryItem CreateItem(StackableInventoryItemDefinition definition, long quantity = 1L)
    Parameters
    Type Name Description
    StackableInventoryItemDefinition definition

    The StackableInventoryItemDefinition to assign to this Item.

    Int64 quantity

    Quantity of the newly-created stackable item which defaults to 1.

    Returns
    Type Description
    StackableInventoryItem

    The newly created item based on specified StackableInventoryItemDefinition.

    CreateList()

    Create an empty ItemList.

    Declaration
    ItemList CreateList()
    Returns
    Type Description
    ItemList

    Empty ItemList to store InventoryItems.

    CreateMap()

    Create an empty ItemMap.

    Declaration
    ItemMap CreateMap()
    Returns
    Type Description
    ItemMap

    Empty ItemMap to store InventoryItems.

    Delete(IItemCollection)

    Deletes specified IItemCollection.

    Declaration
    bool Delete(IItemCollection collection)
    Parameters
    Type Name Description
    IItemCollection collection

    IItemCollection to delete from IInventoryManager.

    Returns
    Type Description
    Boolean

    true if item map is found and deleted, else false.

    Delete(InventoryItem)

    This method will delete the given item.

    Declaration
    bool Delete(InventoryItem item)
    Parameters
    Type Name Description
    InventoryItem item

    The Item instance we want to delete.

    Returns
    Type Description
    Boolean

    Whether or not the Item was successfully deleted.

    Delete(InventoryItemDefinition, ICollection<InventoryItem>, Boolean)

    This method will delete the items that uses the given definition.

    Declaration
    int Delete(InventoryItemDefinition definition, ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    InventoryItemDefinition definition

    The InventoryItemDefinition we want to delete.

    ICollection<InventoryItem> target

    The target collection where deleted items are copied to.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The amount of items that were deleted.

    DeleteAllCollections(ICollection<IItemCollection>, Boolean)

    Deletes all IItemCollections.

    Declaration
    int DeleteAllCollections(ICollection<IItemCollection> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    ICollection<IItemCollection> target

    The target collection te deleted collections are copied to.

    Boolean clearTarget

    If true, it cleats the target collection before populating.

    Returns
    Type Description
    Int32

    The number of collections deleted.

    DeleteAllItems(ICollection<InventoryItem>, Boolean)

    Deletes all the items from the player inventory.

    Declaration
    int DeleteAllItems(ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    ICollection<InventoryItem> target

    The target collection the deleted items are copied to.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of items deleted.

    FindCollection<TCollection>(String)

    Finds collection of specified type using id.

    Declaration
    TCollection FindCollection<TCollection>(string id)
        where TCollection : class, IItemCollection
    Parameters
    Type Name Description
    String id

    Id to search for.

    Returns
    Type Description
    TCollection

    IItemCollection found or null if collection does not exist.

    Type Parameters
    Name Description
    TCollection

    Type of collection to search for.

    FindItem(String)

    Returns an item with the Id wanted.

    Declaration
    InventoryItem FindItem(string id)
    Parameters
    Type Name Description
    String id

    The identifier of the item wanted.

    Returns
    Type Description
    InventoryItem

    Returns the item with the given id if it exists; return null otherwise.

    FindItems(Predicate<InventoryItem>, ICollection<InventoryItem>, Boolean)

    Gets filtered items.

    Declaration
    int FindItems(Predicate<InventoryItem> filter, ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    Predicate<InventoryItem> filter

    The predicate to filter the items.

    ICollection<InventoryItem> target

    The target collection the filtered items are copied to.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of items passing the filter.

    FindItems(InventoryItemDefinition, ICollection<InventoryItem>, Boolean)

    Gets items filtered with the specified definition.

    Declaration
    int FindItems(InventoryItemDefinition definition, ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    InventoryItemDefinition definition

    The InventoryItemDefinition used to filter the items.

    ICollection<InventoryItem> target

    The target collection where filtered items are copied.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of InventoryItem instances found.

    Exceptions
    Type Condition
    ArgumentNullException

    If definition is null.

    FindItems(Tag, ICollection<InventoryItem>, Boolean)

    Gets items filtered with the specified tag.

    Declaration
    int FindItems(Tag tag, ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    Tag tag

    The tag used to filter the items.

    ICollection<InventoryItem> target

    The target collection where filtered items are copied.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of items found.

    Exceptions
    Type Condition
    ArgumentNullException

    If tag is null.

    FindItems<TState>(Func<TState, InventoryItem, Boolean>, TState, ICollection<InventoryItem>, Boolean)

    Gets filtered items.

    Declaration
    int FindItems<TState>(Func<TState, InventoryItem, bool> filter, TState state, ICollection<InventoryItem> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    Func<TState, InventoryItem, Boolean> filter

    The predicate to filter the items.

    TState state

    An object representing data to be used by the filter.

    ICollection<InventoryItem> target

    The target collection the filtered items are copied to.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of items passing the filter.

    Type Parameters
    Name Description
    TState

    The type of the state parameter.

    GetCollections(ICollection<IItemCollection>, Boolean)

    Fills target ICollection<T> with all IItemCollections.

    Declaration
    int GetCollections(ICollection<IItemCollection> target = null, bool clearTarget = true)
    Parameters
    Type Name Description
    ICollection<IItemCollection> target

    The target collection the IItemCollection instances are copied to.

    Boolean clearTarget

    If true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    Count of IItemCollections found.

    GetItems(ICollection<InventoryItem>, Boolean)

    Fills the given list with all items in the manager.

    Declaration
    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 true, it clears the target collection before populating.

    Returns
    Type Description
    Int32

    The number of items found.

    GetQuantity(StackableInventoryItem)

    Get specified StackableInventoryItem's quantity.

    Declaration
    long GetQuantity(StackableInventoryItem item)
    Parameters
    Type Name Description
    StackableInventoryItem item

    StackableInventoryItem to get quantity of.

    Returns
    Type Description
    Int64

    Quantity of items in StackableInventoryItem.

    GetTotalQuantity(InventoryItemDefinition)

    Iterate inventory and return total quantity of specified InventoryItemDefinition. Note: if items are StackableInventoryItem then total of all items in all stacks is calculated.

    Declaration
    long GetTotalQuantity(InventoryItemDefinition itemDefinition)
    Parameters
    Type Name Description
    InventoryItemDefinition itemDefinition

    InventoryItemDefinition to total.

    Returns
    Type Description
    Int64

    Total quantity of specified InventoryItemDefinition.

    SetQuantity(StackableInventoryItem, Int64)

    Set specified StackableInventoryItem's quantity. Ensures new quanitity is permissible before setting; returns false on failure.

    Declaration
    bool SetQuantity(StackableInventoryItem item, long quantity)
    Parameters
    Type Name Description
    StackableInventoryItem item

    StackableInventoryItem to change quantity upon.

    Int64 quantity

    Requested new quantity.

    Returns
    Type Description
    Boolean

    true if quantity change is permissible and changed, else false.

    Events

    collectionAdded

    Event fired whenever any IItemCollection is added.

    Declaration
    event Action<IItemCollection> collectionAdded
    Event Type
    Type Description
    Action<IItemCollection>

    collectionDeleted

    Event fired whenever any IItemCollection is deleted.

    Declaration
    event Action<IItemCollection> collectionDeleted
    Event Type
    Type Description
    Action<IItemCollection>

    itemAdded

    Event fired whenever a new Inventory Item is added.

    Declaration
    event Action<InventoryItem> itemAdded
    Event Type
    Type Description
    Action<InventoryItem>

    itemAddedToCollection

    Event fired whenever an InventoryItem is added to an IItemCollection.

    Declaration
    event Action<IItemCollection, InventoryItem> itemAddedToCollection
    Event Type
    Type Description
    Action<IItemCollection, InventoryItem>

    itemDeleted

    Event fired whenever an Inventory Item is deleted.

    Declaration
    event Action<InventoryItem> itemDeleted
    Event Type
    Type Description
    Action<InventoryItem>

    itemMutablePropertyChanged

    Event fired whenever any InventoryItem Property changes.

    Declaration
    event Action<PropertyChangedEventArgs> itemMutablePropertyChanged
    Event Type
    Type Description
    Action<PropertyChangedEventArgs>

    itemQuantityChanged

    Event fired whenever a StackableInventoryItem quantity changes.

    Declaration
    event Action<IQuantifiable, long> itemQuantityChanged
    Event Type
    Type Description
    Action<IQuantifiable, Int64>

    itemRemovedFromCollection

    Event fired whenever an InventoryItem is removed from an IItemCollection.

    Declaration
    event Action<IItemCollection, InventoryItem> itemRemovedFromCollection
    Event Type
    Type Description
    Action<IItemCollection, InventoryItem>
    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on 16 June 2021