Class InventoryItem | Game Foundation | 0.8.0-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Class InventoryItem

    Item handled by the IInventoryManager.

    Inheritance
    Object
    InventoryItem
    StackableInventoryItem
    Namespace: UnityEngine.GameFoundation
    Syntax
    public class InventoryItem : IEquatable<InventoryItem>, IComparable<InventoryItem>, ITradable

    Fields

    m_ItemCollections

    List of all IItemCollection (either ItemList or ItemMap instances that this item has been added to.

    Declaration
    protected List<IItemCollection> m_ItemCollections
    Field Value
    Type Description
    List<IItemCollection>

    Properties

    definition

    Declaration
    public InventoryItemDefinition definition { get; }
    Property Value
    Type Description
    InventoryItemDefinition
    Exceptions
    Type Condition
    NullReferenceException

    If this item has been discarded.

    hasBeenDiscarded

    Determines if this item 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

    true if the item has been removed from Game Foundation.

    id

    Declaration
    public string id { get; }
    Property Value
    Type Description
    String
    Exceptions
    Type Condition
    NullReferenceException

    If this item has been discarded.

    Methods

    AdjustMutableProperty(String, Property)

    Adjust the value of the mutable property with the given key by adding the given change to its current value. Work only with numeric properties.

    Declaration
    public Property AdjustMutableProperty(string key, Property change)
    Parameters
    Type Name Description
    String key

    Identifier of the mutable property to get the value of.

    Property change

    Change to apply to the current value of the mutable property.

    Returns
    Type Description
    Property

    The new value of the mutable property.

    Exceptions
    Type Condition
    ArgumentException

    If the key parameter is null, empty, or whitespace.

    NullReferenceException

    If this item has been discarded.

    PropertyNotFoundException

    If there is no mutable property with the given key in this item.

    InvalidOperationException

    Thrown if the mutable property's type isn't a numeric type.

    AssertActive()

    Throws a NullReferenceException if this InventoryItem is discarded.

    Declaration
    [ExcludeFromDocs]
    protected void AssertActive()

    Equals(Object)

    Tells whether this InventoryItem instance equals obj.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj

    The other object to compare this instance with.

    Returns
    Type Description
    Boolean

    true if equals, false otherwise.

    Overrides
    Object.Equals(Object)

    GetDefaultValueOfMutableProperty(String)

    Get the default value of the mutable property with the given propertyKey.

    Declaration
    public Property GetDefaultValueOfMutableProperty(string propertyKey)
    Parameters
    Type Name Description
    String propertyKey

    Identifier of the mutable property to get the value of.

    Returns
    Type Description
    Property

    The default value of the mutable property with the given propertyKey.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if the given propertyKey is null, empty, or whitespace.

    PropertyNotFoundException

    Thrown if there is no mutable property with the given propertyKey in this item.

    GetDefaultValuesOfMutableProperties()

    Get all default properties stored in this definition.

    Declaration
    public Dictionary<string, Property> GetDefaultValuesOfMutableProperties()
    Returns
    Type Description
    Dictionary<String, Property>

    Return a new dictionary containing all properties stored in this definition. The returned dictionary is never null.

    GetDefaultValuesOfMutableProperties(Dictionary<String, Property>)

    Get all default values of mutable properties stored in this definition.

    Declaration
    public void GetDefaultValuesOfMutableProperties(Dictionary<string, Property> target)
    Parameters
    Type Name Description
    Dictionary<String, Property> target

    The dictionary to fill with the mutable properties stored in this definition. It is cleared before being filled.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the given target is null.

    GetHashCode()

    Gets the hash code of this InventoryItem instance. Returns the hash code of its id.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    The hash code of this InventoryItem instance.

    Overrides
    Object.GetHashCode()

    GetItemCollections(ICollection<IItemCollection>, Boolean)

    Fill specified ICollection<T> with all IItemCollections that this item is contained in.

    Declaration
    public int GetItemCollections(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.

    GetMutableProperties()

    Get all mutable properties stored in this item.

    Declaration
    public Dictionary<string, Property> GetMutableProperties()
    Returns
    Type Description
    Dictionary<String, Property>

    Return a new dictionary containing all mutable properties stored in this item. The returned dictionary is never null.

    GetMutableProperties(Dictionary<String, Property>)

    Get all mutable properties stored in this item.

    Declaration
    public void GetMutableProperties(Dictionary<string, Property> target)
    Parameters
    Type Name Description
    Dictionary<String, Property> target

    The dictionary to fill with the mutable properties stored in this item. It is cleared before being filled.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the given target is null.

    GetMutableProperty(String)

    Get the value of the mutable property with the given key.

    Declaration
    public Property GetMutableProperty(string key)
    Parameters
    Type Name Description
    String key

    Identifier of the mutable property to get the value of.

    Returns
    Type Description
    Property

    The value of the mutable property with the given key.

    Exceptions
    Type Condition
    ArgumentException

    If the key parameter is null, empty, or whitespace.

    NullReferenceException

    If this item has been discarded.

    PropertyNotFoundException

    If there is no mutable property with the given key in this item.

    HasMutableProperty(String)

    Check if this item has a mutable property for the given key.

    Declaration
    public bool HasMutableProperty(string key)
    Parameters
    Type Name Description
    String key

    The identifier of the mutable property to look for.

    Returns
    Type Description
    Boolean

    true if this item has a mutable property with the given key; false otherwise.

    Exceptions
    Type Condition
    ArgumentException

    If the key parameter is null, empty, or whitespace.

    NullReferenceException

    If this item has been discarded.

    RemoveFromAllItemCollections()

    Remove this InventoryItem from all IItemCollection instances (if any).

    Declaration
    public void RemoveFromAllItemCollections()

    ResetMutableProperty(String)

    Reset the mutable property with the given key to its default value.

    Declaration
    public Property ResetMutableProperty(string key)
    Parameters
    Type Name Description
    String key

    The identifier of the mutable property to reset.

    Returns
    Type Description
    Property

    Return the new mutable property's value after its reset.

    Exceptions
    Type Condition
    NullReferenceException

    If this has been discarded.

    ArgumentNullException

    If the key is null, empty, or whitespace.

    PropertyNotFoundException

    If there is no mutable property with the given key in this item.

    SetMutableProperty(String, Property)

    Set the mutable property with the given key with the given value.

    Declaration
    public Property SetMutableProperty(string key, Property value)
    Parameters
    Type Name Description
    String key

    Identifier of the mutable property to get the value of.

    Property value

    The value to assign to the mutable property.

    Returns
    Type Description
    Property

    The new value of the mutable property.

    Exceptions
    Type Condition
    ArgumentException

    If the key parameter is null, empty, or whitespace.

    NullReferenceException

    If this item has been discarded.

    PropertyNotFoundException

    If there is no mutable property with the given key in this item.

    PropertyInvalidCastException

    If the given value type is different from the expected type.

    TryGetDefaultValueOfMutableProperty(String, out Property)

    Try to get the default value of the mutable property with the given propertyKey.

    Declaration
    public bool TryGetDefaultValueOfMutableProperty(string propertyKey, out Property property)
    Parameters
    Type Name Description
    String propertyKey

    Identifier of the mutable property to get the value of.

    Property property

    The default value of the searched mutable property, if found.

    Returns
    Type Description
    Boolean

    Returns true if a mutable property with the given propertyKey exists on this item; returns false otherwise.

    TryGetMutableProperty(String, out Property)

    Try to get the value of the mutable property with the given key.

    Declaration
    public bool TryGetMutableProperty(string key, out Property property)
    Parameters
    Type Name Description
    String key

    Identifier of the mutable property to get the value of.

    Property property

    The value of the searched mutable property, if found.

    Returns
    Type Description
    Boolean

    Returns true if a mutable property with the given key exists on this item; returns false otherwise.

    Exceptions
    Type Condition
    NullReferenceException

    If this item has been discarded.

    Events

    mutablePropertyChanged

    Event triggered when a mutable property is updated.

    Declaration
    public event Action<PropertyChangedEventArgs> mutablePropertyChanged
    Event Type
    Type Description
    Action<PropertyChangedEventArgs>
    In This Article
    • Fields
      • m_ItemCollections
    • Properties
      • definition
      • hasBeenDiscarded
      • id
    • Methods
      • AdjustMutableProperty(String, Property)
      • AssertActive()
      • Equals(Object)
      • GetDefaultValueOfMutableProperty(String)
      • GetDefaultValuesOfMutableProperties()
      • GetDefaultValuesOfMutableProperties(Dictionary<String, Property>)
      • GetHashCode()
      • GetItemCollections(ICollection<IItemCollection>, Boolean)
      • GetMutableProperties()
      • GetMutableProperties(Dictionary<String, Property>)
      • GetMutableProperty(String)
      • HasMutableProperty(String)
      • RemoveFromAllItemCollections()
      • ResetMutableProperty(String)
      • SetMutableProperty(String, Property)
      • TryGetDefaultValueOfMutableProperty(String, out Property)
      • TryGetMutableProperty(String, out Property)
    • Events
      • mutablePropertyChanged
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023