Inventory Engine v4.2
Loading...
Searching...
No Matches
MoreMountains.InventoryEngine.Inventory Class Reference

Base inventory class. More...

Inherits MonoBehaviour, MoreMountains.Tools.MMEventListener< T >, and MoreMountains.Tools.MMEventListener< T >.

Public Types

enum  InventoryTypes { Main , Equipment }
 The different possible inventory types, main are regular, equipment will have special behaviours (use them for slots where you put the equipped weapon/armor/etc). More...

Public Member Functions

int NumberOfStackableSlots (string searchedItemID, int maxStackSize)
virtual void SetOwner (GameObject newOwner)
 Sets the owner of this inventory, useful to apply the effect of an item for example.
virtual bool AddItem (InventoryItem itemToAdd, int quantity)
 Tries to add an item of the specified type.
virtual bool AddItemAt (InventoryItem itemToAdd, int quantity, int destinationIndex)
 Adds the specified quantity of the specified item to the inventory, at the destination index of choice.
virtual bool MoveItem (int startIndex, int endIndex)
 Tries to move the item at the first parameter slot to the second slot.
virtual bool MoveItemToInventory (int startIndex, Inventory targetInventory, int endIndex=-1)
 This method lets you move the item at startIndex to the chosen targetInventory, at an optional endIndex there.
virtual bool RemoveItem (int i, int quantity)
 Removes the specified item from the inventory.
virtual bool RemoveItemByID (string itemID, int quantity)
 Removes the specified quantity of the item matching the specified itemID.
virtual bool DestroyItem (int i)
 Destroys the item stored at index i.
virtual void EmptyInventory ()
 Empties the current state of the inventory.
virtual int CapMaxQuantity (InventoryItem itemToAdd, int newQuantity)
 Returns the max value of a specific item that can be added to this inventory without exceeding the max quantity defined on the item.
virtual void ResizeArray (int newSize)
 Resizes the array to the specified new size.
virtual int GetQuantity (string searchedItemID)
 Returns the total quantity of items matching the specified name.
virtual List< int > InventoryContains (string searchedItemID)
 Returns a list of all the items in the inventory that match the specified name.
virtual List< int > InventoryContains (MoreMountains.InventoryEngine.ItemClasses searchedClass)
 Returns a list of all the items in the inventory that match the specified class.
virtual void SaveInventory ()
 Saves the inventory to a file.
virtual void LoadSavedInventory ()
 Tries to load the inventory if a file is present.
virtual void ResetSavedInventory ()
 Destroys any save file.
virtual bool UseItem (InventoryItem item, int index, InventorySlot slot=null)
 Triggers the use and potential consumption of the item passed in parameter.
virtual bool UseItem (string itemName)
 Triggers the use of an item, as specified by its name.
virtual void EquipItem (InventoryItem item, int index, InventorySlot slot=null)
 Equips the item at the specified slot.
virtual void DropItem (InventoryItem item, int index, InventorySlot slot=null)
 Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character.
virtual void DestroyItem (InventoryItem item, int index, InventorySlot slot=null)
virtual void UnEquipItem (InventoryItem item, int index, InventorySlot slot=null)
virtual void OnMMEvent (MMInventoryEvent inventoryEvent)
 Catches inventory events and acts on them.
virtual void OnMMEvent (MMGameEvent gameEvent)
 When we catch an MMGameEvent, we do stuff based on its name.
Public Member Functions inherited from MoreMountains.Tools.MMEventListener< T >
void OnMMEvent (T eventType)

Static Public Member Functions

static Inventory FindInventory (string inventoryName, string playerID)
 Returns (if found) an inventory matching the searched name and playerID.

Public Attributes

string PlayerID = "Player1"
 a unique ID used to identify the owner of this inventory
InventoryItem[] Content
 the complete list of inventory items in this inventory
InventoryTypes InventoryType = InventoryTypes.Main
 whether this inventory is a main inventory or equipment one
Transform TargetTransform
 the transform at which objects will be spawned when dropped
bool Persistent = true
 whether this inventory will be saved and loaded
bool ResetThisInventorySaveOnStart = false
 whether or not this inventory should be reset on start
bool DrawContentInInspector = false
 If true, will draw the contents of the inventory in its inspector.

Static Public Attributes

static List< InventoryRegisteredInventories
static string _resourceItemPath = "Items/"
static string _saveFolderName = "InventoryEngine/"
static string _saveFileExtension = ".inventory"

Protected Member Functions

virtual void Awake ()
 On Awake we register this inventory.
virtual void RegisterInventory ()
 Registers this inventory so other scripts can access it later on.
virtual bool AddItemToArray (InventoryItem itemToAdd, int quantity)
 Adds the item to content array.
virtual bool RemoveItemFromArray (int i)
 Removes the item at index i from the array.
virtual void FillSerializedInventory (SerializedInventory serializedInventory)
 Fills the serialized inventory for storage.
virtual void ExtractSerializedInventory (SerializedInventory serializedInventory)
 Extracts the serialized inventory from a file content.
virtual string DetermineSaveName ()
virtual void OnEnable ()
 On enable, we start listening for MMGameEvents.
virtual void OnDisable ()
 On disable, we stop listening for MMGameEvents.

Static Protected Member Functions

static void InitializeStatics ()

Protected Attributes

InventoryItem _loadedInventoryItem

Properties

virtual GameObject Owner [get, set]
 the owner of the inventory (for games where you have multiple characters)
virtual int NumberOfFreeSlots [get]
 The number of free slots in this inventory.
virtual bool IsFull [get]
 whether or not the inventory is full (doesn't have any remaining free slots)
int NumberOfFilledSlots [get]
 The number of filled slots.

Detailed Description

Base inventory class.

Will handle storing items, saving and loading its content, adding items to it, removing items, equipping them, etc.

Member Enumeration Documentation

◆ InventoryTypes

The different possible inventory types, main are regular, equipment will have special behaviours (use them for slots where you put the equipped weapon/armor/etc).

Enumerator
Main 
Equipment 

Member Function Documentation

◆ AddItem()

virtual bool MoreMountains.InventoryEngine.Inventory.AddItem ( InventoryItem itemToAdd,
int quantity )
virtual

Tries to add an item of the specified type.

Note that this is name based.

Returns
true, if item was added, false if it couldn't be added (item null, inventory full).
Parameters
itemToAddItem to add.

◆ AddItemAt()

virtual bool MoreMountains.InventoryEngine.Inventory.AddItemAt ( InventoryItem itemToAdd,
int quantity,
int destinationIndex )
virtual

Adds the specified quantity of the specified item to the inventory, at the destination index of choice.

Parameters
itemToAdd
quantity
destinationIndex
Returns

◆ AddItemToArray()

virtual bool MoreMountains.InventoryEngine.Inventory.AddItemToArray ( InventoryItem itemToAdd,
int quantity )
protectedvirtual

Adds the item to content array.

Returns
true, if item to array was added, false otherwise.
Parameters
itemToAddItem to add.
quantityQuantity.

◆ Awake()

virtual void MoreMountains.InventoryEngine.Inventory.Awake ( )
protectedvirtual

On Awake we register this inventory.

◆ CapMaxQuantity()

virtual int MoreMountains.InventoryEngine.Inventory.CapMaxQuantity ( InventoryItem itemToAdd,
int newQuantity )
virtual

Returns the max value of a specific item that can be added to this inventory without exceeding the max quantity defined on the item.

Parameters
itemToAdd
newQuantity
Returns

◆ DestroyItem() [1/2]

virtual bool MoreMountains.InventoryEngine.Inventory.DestroyItem ( int i)
virtual

Destroys the item stored at index i.

Returns
true, if item was destroyed, false otherwise.
Parameters
iThe index.

◆ DestroyItem() [2/2]

virtual void MoreMountains.InventoryEngine.Inventory.DestroyItem ( InventoryItem item,
int index,
InventorySlot slot = null )
virtual

◆ DetermineSaveName()

virtual string MoreMountains.InventoryEngine.Inventory.DetermineSaveName ( )
protectedvirtual

◆ DropItem()

virtual void MoreMountains.InventoryEngine.Inventory.DropItem ( InventoryItem item,
int index,
InventorySlot slot = null )
virtual

Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character.

Parameters
itemItem.
indexIndex.
slotSlot.

◆ EmptyInventory()

virtual void MoreMountains.InventoryEngine.Inventory.EmptyInventory ( )
virtual

Empties the current state of the inventory.

◆ EquipItem()

virtual void MoreMountains.InventoryEngine.Inventory.EquipItem ( InventoryItem item,
int index,
InventorySlot slot = null )
virtual

Equips the item at the specified slot.

Parameters
itemItem.
indexIndex.
slotSlot.

◆ ExtractSerializedInventory()

virtual void MoreMountains.InventoryEngine.Inventory.ExtractSerializedInventory ( SerializedInventory serializedInventory)
protectedvirtual

Extracts the serialized inventory from a file content.

Parameters
serializedInventorySerialized inventory.

◆ FillSerializedInventory()

virtual void MoreMountains.InventoryEngine.Inventory.FillSerializedInventory ( SerializedInventory serializedInventory)
protectedvirtual

Fills the serialized inventory for storage.

Parameters
serializedInventorySerialized inventory.

◆ FindInventory()

Inventory MoreMountains.InventoryEngine.Inventory.FindInventory ( string inventoryName,
string playerID )
static

Returns (if found) an inventory matching the searched name and playerID.

Parameters
inventoryName
playerID
Returns

◆ GetQuantity()

virtual int MoreMountains.InventoryEngine.Inventory.GetQuantity ( string searchedItemID)
virtual

Returns the total quantity of items matching the specified name.

Returns
The quantity.
Parameters
searchedItemSearched item.

◆ InitializeStatics()

void MoreMountains.InventoryEngine.Inventory.InitializeStatics ( )
staticprotected

◆ InventoryContains() [1/2]

virtual List< int > MoreMountains.InventoryEngine.Inventory.InventoryContains ( MoreMountains.InventoryEngine.ItemClasses searchedClass)
virtual

Returns a list of all the items in the inventory that match the specified class.

Returns
A list of item matching the search criteria.
Parameters
searchedTypeThe searched type.

◆ InventoryContains() [2/2]

virtual List< int > MoreMountains.InventoryEngine.Inventory.InventoryContains ( string searchedItemID)
virtual

Returns a list of all the items in the inventory that match the specified name.

Returns
A list of item matching the search criteria.
Parameters
searchedTypeThe searched type.

◆ LoadSavedInventory()

virtual void MoreMountains.InventoryEngine.Inventory.LoadSavedInventory ( )
virtual

Tries to load the inventory if a file is present.

◆ MoveItem()

virtual bool MoreMountains.InventoryEngine.Inventory.MoveItem ( int startIndex,
int endIndex )
virtual

Tries to move the item at the first parameter slot to the second slot.

Returns
true, if item was moved, false otherwise.
Parameters
startIndexStart index.
endIndexEnd index.

◆ MoveItemToInventory()

virtual bool MoreMountains.InventoryEngine.Inventory.MoveItemToInventory ( int startIndex,
Inventory targetInventory,
int endIndex = -1 )
virtual

This method lets you move the item at startIndex to the chosen targetInventory, at an optional endIndex there.

Parameters
startIndex
targetInventory
endIndex
Returns

◆ NumberOfStackableSlots()

int MoreMountains.InventoryEngine.Inventory.NumberOfStackableSlots ( string searchedItemID,
int maxStackSize )

◆ OnDisable()

virtual void MoreMountains.InventoryEngine.Inventory.OnDisable ( )
protectedvirtual

On disable, we stop listening for MMGameEvents.

You may want to extend that to stop listening to other types of events.

◆ OnEnable()

virtual void MoreMountains.InventoryEngine.Inventory.OnEnable ( )
protectedvirtual

On enable, we start listening for MMGameEvents.

You may want to extend that to listen to other types of events.

◆ OnMMEvent() [1/2]

virtual void MoreMountains.InventoryEngine.Inventory.OnMMEvent ( MMGameEvent gameEvent)
virtual

When we catch an MMGameEvent, we do stuff based on its name.

Parameters
gameEventGame event.

◆ OnMMEvent() [2/2]

virtual void MoreMountains.InventoryEngine.Inventory.OnMMEvent ( MMInventoryEvent inventoryEvent)
virtual

Catches inventory events and acts on them.

Parameters
inventoryEventInventory event.

◆ RegisterInventory()

virtual void MoreMountains.InventoryEngine.Inventory.RegisterInventory ( )
protectedvirtual

Registers this inventory so other scripts can access it later on.

◆ RemoveItem()

virtual bool MoreMountains.InventoryEngine.Inventory.RemoveItem ( int i,
int quantity )
virtual

Removes the specified item from the inventory.

Returns
true, if item was removed, false otherwise.
Parameters
itemToRemoveItem to remove.

◆ RemoveItemByID()

virtual bool MoreMountains.InventoryEngine.Inventory.RemoveItemByID ( string itemID,
int quantity )
virtual

Removes the specified quantity of the item matching the specified itemID.

Parameters
itemID
quantity
Returns

◆ RemoveItemFromArray()

virtual bool MoreMountains.InventoryEngine.Inventory.RemoveItemFromArray ( int i)
protectedvirtual

Removes the item at index i from the array.

Returns
true, if item from array was removed, false otherwise.
Parameters
iThe index.

◆ ResetSavedInventory()

virtual void MoreMountains.InventoryEngine.Inventory.ResetSavedInventory ( )
virtual

Destroys any save file.

◆ ResizeArray()

virtual void MoreMountains.InventoryEngine.Inventory.ResizeArray ( int newSize)
virtual

Resizes the array to the specified new size.

Parameters
newSizeNew size.

◆ SaveInventory()

virtual void MoreMountains.InventoryEngine.Inventory.SaveInventory ( )
virtual

Saves the inventory to a file.

◆ SetOwner()

virtual void MoreMountains.InventoryEngine.Inventory.SetOwner ( GameObject newOwner)
virtual

Sets the owner of this inventory, useful to apply the effect of an item for example.

Parameters
newOwnerNew owner.

◆ UnEquipItem()

virtual void MoreMountains.InventoryEngine.Inventory.UnEquipItem ( InventoryItem item,
int index,
InventorySlot slot = null )
virtual

◆ UseItem() [1/2]

virtual bool MoreMountains.InventoryEngine.Inventory.UseItem ( InventoryItem item,
int index,
InventorySlot slot = null )
virtual

Triggers the use and potential consumption of the item passed in parameter.

You can also specify the item's slot (optional) and index.

Parameters
itemItem.
slotSlot.
indexIndex.

◆ UseItem() [2/2]

virtual bool MoreMountains.InventoryEngine.Inventory.UseItem ( string itemName)
virtual

Triggers the use of an item, as specified by its name.

Prefer this signature over the previous one if you don't particularly care what slot the item will be taken from in case of duplicates.

Parameters
itemName
Returns

Member Data Documentation

◆ _loadedInventoryItem

InventoryItem MoreMountains.InventoryEngine.Inventory._loadedInventoryItem
protected

◆ _resourceItemPath

string MoreMountains.InventoryEngine.Inventory._resourceItemPath = "Items/"
static

◆ _saveFileExtension

string MoreMountains.InventoryEngine.Inventory._saveFileExtension = ".inventory"
static

◆ _saveFolderName

string MoreMountains.InventoryEngine.Inventory._saveFolderName = "InventoryEngine/"
static

◆ Content

InventoryItem [] MoreMountains.InventoryEngine.Inventory.Content

the complete list of inventory items in this inventory

◆ DrawContentInInspector

bool MoreMountains.InventoryEngine.Inventory.DrawContentInInspector = false

If true, will draw the contents of the inventory in its inspector.

◆ InventoryType

InventoryTypes MoreMountains.InventoryEngine.Inventory.InventoryType = InventoryTypes.Main

whether this inventory is a main inventory or equipment one

◆ Persistent

bool MoreMountains.InventoryEngine.Inventory.Persistent = true

whether this inventory will be saved and loaded

◆ PlayerID

string MoreMountains.InventoryEngine.Inventory.PlayerID = "Player1"

a unique ID used to identify the owner of this inventory

◆ RegisteredInventories

List<Inventory> MoreMountains.InventoryEngine.Inventory.RegisteredInventories
static

◆ ResetThisInventorySaveOnStart

bool MoreMountains.InventoryEngine.Inventory.ResetThisInventorySaveOnStart = false

whether or not this inventory should be reset on start

◆ TargetTransform

Transform MoreMountains.InventoryEngine.Inventory.TargetTransform

the transform at which objects will be spawned when dropped

Property Documentation

◆ IsFull

virtual bool MoreMountains.InventoryEngine.Inventory.IsFull
get

whether or not the inventory is full (doesn't have any remaining free slots)

◆ NumberOfFilledSlots

int MoreMountains.InventoryEngine.Inventory.NumberOfFilledSlots
get

The number of filled slots.

◆ NumberOfFreeSlots

virtual int MoreMountains.InventoryEngine.Inventory.NumberOfFreeSlots
get

The number of free slots in this inventory.

◆ Owner

virtual GameObject MoreMountains.InventoryEngine.Inventory.Owner
getset

the owner of the inventory (for games where you have multiple characters)


The documentation for this class was generated from the following file: