Class InventoryItem
Item handled by the IInventoryManager.
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 |
|
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 |
NullReferenceException | If this item has been discarded. |
PropertyNotFoundException | If there is no mutable property with the given |
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 |
|
Overrides
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 |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the given |
PropertyNotFoundException | Thrown if there is no mutable property with the given |
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 |
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
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 |
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 |
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 |
Exceptions
Type | Condition |
---|---|
ArgumentException | If the |
NullReferenceException | If this item has been discarded. |
PropertyNotFoundException | If there is no mutable property with the given |
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 |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If the |
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 |
PropertyNotFoundException | If there is no mutable property with the given |
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 |
NullReferenceException | If this item has been discarded. |
PropertyNotFoundException | If there is no mutable property with the given |
PropertyInvalidCastException | If the given |
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 |
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 |
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> |