TopDown Engine
v4.2
|
Base inventory class. Will handle storing items, saving and loading its content, adding items to it, removing items, equipping them, etc. More...
Public Types | |
enum | InventoryTypes { InventoryTypes.Main, InventoryTypes.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. More... | |
virtual bool | AddItem (InventoryItem itemToAdd, int quantity) |
Tries to add an item of the specified type. Note that this is name based. More... | |
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 More... | |
virtual bool | MoveItem (int startIndex, int endIndex) |
Tries to move the item at the first parameter slot to the second slot More... | |
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 More... | |
virtual bool | RemoveItem (int i, int quantity) |
Removes the specified item from the inventory. More... | |
virtual bool | RemoveItemByID (string itemID, int quantity) |
Removes the specified quantity of the item matching the specified itemID More... | |
virtual bool | DestroyItem (int i) |
Destroys the item stored at index i More... | |
virtual void | EmptyInventory () |
Empties the current state of the inventory. More... | |
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 More... | |
virtual void | ResizeArray (int newSize) |
Resizes the array to the specified new size More... | |
virtual int | GetQuantity (string searchedItemID) |
Returns the total quantity of items matching the specified name More... | |
virtual List< int > | InventoryContains (string searchedItemID) |
Returns a list of all the items in the inventory that match the specified name More... | |
virtual List< int > | InventoryContains (MoreMountains.InventoryEngine.ItemClasses searchedClass) |
Returns a list of all the items in the inventory that match the specified class More... | |
virtual void | SaveInventory () |
Saves the inventory to a file More... | |
virtual void | LoadSavedInventory () |
Tries to load the inventory if a file is present More... | |
virtual void | ResetSavedInventory () |
Destroys any save file More... | |
virtual bool | UseItem (InventoryItem item, int index, InventorySlot slot=null) |
Triggers the use and potential consumption of the item passed in parameter. You can also specify the item's slot (optional) and index. More... | |
virtual bool | UseItem (string itemName) |
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. More... | |
virtual void | EquipItem (InventoryItem item, int index, InventorySlot slot=null) |
Equips the item at the specified slot More... | |
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 More... | |
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 More... | |
virtual void | OnMMEvent (MMGameEvent gameEvent) |
When we catch an MMGameEvent, we do stuff based on its name More... | |
Public Member Functions inherited from MoreMountains.Tools.MMEventListener< MMInventoryEvent > | |
void | OnMMEvent (T eventType) |
Public Member Functions inherited from MoreMountains.Tools.MMEventListener< MMGameEvent > | |
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 More... | |
Public Attributes | |
string | PlayerID = "Player1" |
a unique ID used to identify the owner of this inventory More... | |
InventoryItem[] | Content |
the complete list of inventory items in this inventory More... | |
InventoryTypes | InventoryType = InventoryTypes.Main |
whether this inventory is a main inventory or equipment one More... | |
Transform | TargetTransform |
the transform at which objects will be spawned when dropped More... | |
bool | Persistent = true |
whether this inventory will be saved and loaded More... | |
bool | ResetThisInventorySaveOnStart = false |
whether or not this inventory should be reset on start More... | |
bool | DrawContentInInspector = false |
If true, will draw the contents of the inventory in its inspector. More... | |
virtual int | NumberOfFreeSlots => Content.Length - NumberOfFilledSlots |
The number of free slots in this inventory. More... | |
virtual bool | IsFull => NumberOfFreeSlots <= 0 |
whether or not the inventory is full (doesn't have any remaining free slots) More... | |
Static Public Attributes | |
static List< Inventory > | RegisteredInventories |
static string | _resourceItemPath = "Items/" |
static string | _saveFolderName = "InventoryEngine/" |
static string | _saveFileExtension = ".inventory" |
Protected Member Functions | |
virtual void | Awake () |
On Awake we register this inventory More... | |
virtual void | RegisterInventory () |
Registers this inventory so other scripts can access it later on More... | |
virtual bool | AddItemToArray (InventoryItem itemToAdd, int quantity) |
Adds the item to content array. More... | |
virtual bool | RemoveItemFromArray (int i) |
Removes the item at index i from the array. More... | |
virtual void | FillSerializedInventory (SerializedInventory serializedInventory) |
Fills the serialized inventory for storage More... | |
virtual void | ExtractSerializedInventory (SerializedInventory serializedInventory) |
Extracts the serialized inventory from a file content More... | |
virtual string | DetermineSaveName () |
virtual void | OnEnable () |
On enable, we start listening for MMGameEvents. You may want to extend that to listen to other types of events. More... | |
virtual void | OnDisable () |
On disable, we stop listening for MMGameEvents. You may want to extend that to stop listening to other types of events. More... | |
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) More... | |
int | NumberOfFilledSlots [get] |
The number of filled slots. More... | |
Base inventory class. Will handle storing items, saving and loading its content, adding items to it, removing items, equipping them, etc.
|
virtual |
Tries to add an item of the specified type. Note that this is name based.
true
, if item was added, false
if it couldn't be added (item null, inventory full).itemToAdd | Item to add. |
|
virtual |
Adds the specified quantity of the specified item to the inventory, at the destination index of choice
itemToAdd | |
quantity | |
destinationIndex |
|
protectedvirtual |
Adds the item to content array.
true
, if item to array was added, false
otherwise.itemToAdd | Item to add. |
quantity | Quantity. |
|
protectedvirtual |
On Awake we register this inventory
|
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
itemToAdd | |
newQuantity |
|
virtual |
Destroys the item stored at index i
true
, if item was destroyed, false
otherwise.i | The index. |
|
virtual |
|
protectedvirtual |
|
virtual |
Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character
item | Item. |
index | Index. |
slot | Slot. |
|
virtual |
Empties the current state of the inventory.
|
virtual |
Equips the item at the specified slot
item | Item. |
index | Index. |
slot | Slot. |
|
protectedvirtual |
Extracts the serialized inventory from a file content
serializedInventory | Serialized inventory. |
|
protectedvirtual |
Fills the serialized inventory for storage
serializedInventory | Serialized inventory. |
|
static |
Returns (if found) an inventory matching the searched name and playerID
inventoryName | |
playerID |
|
virtual |
Returns the total quantity of items matching the specified name
searchedItem | Searched item. |
|
staticprotected |
|
virtual |
Returns a list of all the items in the inventory that match the specified class
searchedType | The searched type. |
|
virtual |
Returns a list of all the items in the inventory that match the specified name
searchedType | The searched type. |
|
virtual |
Tries to load the inventory if a file is present
|
virtual |
Tries to move the item at the first parameter slot to the second slot
true
, if item was moved, false
otherwise.startIndex | Start index. |
endIndex | End index. |
|
virtual |
This method lets you move the item at startIndex to the chosen targetInventory, at an optional endIndex there
startIndex | |
targetInventory | |
endIndex |
int MoreMountains.InventoryEngine.Inventory.NumberOfStackableSlots | ( | string | searchedItemID, |
int | maxStackSize | ||
) |
|
protectedvirtual |
On disable, we stop listening for MMGameEvents. You may want to extend that to stop listening to other types of events.
|
protectedvirtual |
On enable, we start listening for MMGameEvents. You may want to extend that to listen to other types of events.
|
virtual |
When we catch an MMGameEvent, we do stuff based on its name
gameEvent | Game event. |
|
virtual |
Catches inventory events and acts on them
inventoryEvent | Inventory event. |
|
protectedvirtual |
Registers this inventory so other scripts can access it later on
|
virtual |
Removes the specified item from the inventory.
true
, if item was removed, false
otherwise.itemToRemove | Item to remove. |
|
virtual |
Removes the specified quantity of the item matching the specified itemID
itemID | |
quantity |
|
protectedvirtual |
Removes the item at index i from the array.
true
, if item from array was removed, false
otherwise.i | The index. |
|
virtual |
Destroys any save file
|
virtual |
Resizes the array to the specified new size
newSize | New size. |
|
virtual |
Saves the inventory to a file
|
virtual |
Sets the owner of this inventory, useful to apply the effect of an item for example.
newOwner | New owner. |
|
virtual |
|
virtual |
Triggers the use and potential consumption of the item passed in parameter. You can also specify the item's slot (optional) and index.
item | Item. |
slot | Slot. |
index | Index. |
|
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.
itemName |
|
protected |
|
static |
|
static |
|
static |
InventoryItem [] MoreMountains.InventoryEngine.Inventory.Content |
the complete list of inventory items in this inventory
bool MoreMountains.InventoryEngine.Inventory.DrawContentInInspector = false |
If true, will draw the contents of the inventory in its inspector.
InventoryTypes MoreMountains.InventoryEngine.Inventory.InventoryType = InventoryTypes.Main |
whether this inventory is a main inventory or equipment one
virtual bool MoreMountains.InventoryEngine.Inventory.IsFull => NumberOfFreeSlots <= 0 |
whether or not the inventory is full (doesn't have any remaining free slots)
virtual int MoreMountains.InventoryEngine.Inventory.NumberOfFreeSlots => Content.Length - NumberOfFilledSlots |
The number of free slots in this inventory.
bool MoreMountains.InventoryEngine.Inventory.Persistent = true |
whether this inventory will be saved and loaded
string MoreMountains.InventoryEngine.Inventory.PlayerID = "Player1" |
a unique ID used to identify the owner of this inventory
|
static |
bool MoreMountains.InventoryEngine.Inventory.ResetThisInventorySaveOnStart = false |
whether or not this inventory should be reset on start
Transform MoreMountains.InventoryEngine.Inventory.TargetTransform |
the transform at which objects will be spawned when dropped
|
get |
The number of filled slots.
|
getset |
the owner of the inventory (for games where you have multiple characters)