Platformer Pro  2.3.2
A platform game kit for Unity.
PlatformerPro.Inventory Class Reference

Holds Items. Extend to create your own inventories. More...

Inheritance diagram for PlatformerPro.Inventory:
PlatformerPro.PlatformerProMonoBehaviour PlatformerPro.ICoreComponent

Public Member Functions

virtual void Init (Character character)
 Init this instance. Called from awake. More...
 
ItemInstanceData GetItemAt (int position)
 Gets item type and amount at the given position or null if nothing there (or out of range). More...
 
int GetFirstSlotForItem (string itemId)
 Gets the first slot holding the given item. More...
 
int Consume (string itemId, int amount)
 Consume the item with specified key in the given amount. More...
 
ItemTypeData GetItemTypeDataAt (int position)
 Gets the item type data for the item at the given position or null if nothing there (or out of range). More...
 
int AddItem (ItemInstanceData data)
 Add the given item to the inventory. More...
 
int AddItem (string typeId, int amount)
 Add the given item to the inventory. More...
 
int AddItemAt (ItemInstanceData data, int slot)
 Add the given item to the inventory at the given slot. More...
 
virtual int ItemCount (string itemType)
 Gets the number of items of the given type. More...
 
virtual int ItemCount (ItemTypeData type)
 Gets the number of items of the given type. More...
 
void RemoveItemAt (int index, int amount)
 Remove a single item from the given inventory slot. More...
 
void SwitchPositions (int indexA, int indexB)
 Switches the positions of items unless item is a stack of same type it which case it tries to merge the stacks. More...
 
void CleanUpGaps ()
 Shifts positions of items such that there are no gaps in the inventory. More...
 
void CleanUp ()
 Combines stacks until stack max is reached and then shifts positions of items such that there are no gaps in the inventory. More...
 
virtual void ApplySaveData (object t)
 Applies the save data. More...
 
- Public Member Functions inherited from PlatformerPro.PlatformerProMonoBehaviour
virtual void Validate (PlatformerProMonoBehaviour myTarget)
 Override this method if you want to provide custom validation. The actual code should be surrounded by the if UNITY_EDITOR / endif directive. More...
 

Public Attributes

int inventorySize
 Starting size of the inventory. More...
 
bool noGaps
 If true empty inventory spots will cause the inventory to be shifted such as there is no gaps. More...
 

Protected Member Functions

virtual void PostInit ()
 Post Init this instance. Called from Start. More...
 
int AddStackableItem (ItemTypeData type, int amount)
 Add the given item to the inventory. More...
 

Protected Attributes

Character character
 Which character does this inventory belong to. More...
 
InventoryData inventoryData
 The inventory data. More...
 
bool loaded
 Tracks if we have loaded data. More...
 

Properties

ItemInstanceData[] AllItems [get]
 Gets all inventory item data. WARNING: For performance reasons this is not a copy. More...
 
virtual object SaveData [get]
 Gets the data required to save this inventory. More...
 
- Properties inherited from PlatformerPro.PlatformerProMonoBehaviour
virtual string Header [get]
 Gets the header string used to describe the component. More...
 
virtual string DocLink [get]
 Gets a link to documentation site. More...
 
virtual string VideoLink [get]
 Gets a link to a youtube video. More...
 
virtual string Deprecated [get]
 If non-null this component is deprecated. The string shows a message indicating how it should be replaced. More...
 

Detailed Description

Holds Items. Extend to create your own inventories.

Member Function Documentation

◆ AddItem() [1/2]

int PlatformerPro.Inventory.AddItem ( ItemInstanceData  data)

Add the given item to the inventory.

Parameters
dataItem instance data to add

◆ AddItem() [2/2]

int PlatformerPro.Inventory.AddItem ( string  typeId,
int  amount 
)

Add the given item to the inventory.

Parameters
typeIdItem Type identifier.
amountAmount.

◆ AddItemAt()

int PlatformerPro.Inventory.AddItemAt ( ItemInstanceData  data,
int  slot 
)

Add the given item to the inventory at the given slot.

Parameters
dataInventory data.
slotSlot to use.

◆ AddStackableItem()

int PlatformerPro.Inventory.AddStackableItem ( ItemTypeData  type,
int  amount 
)
protected

Add the given item to the inventory.

Parameters
typeItem Type.
amountAmount.

◆ ApplySaveData()

virtual void PlatformerPro.Inventory.ApplySaveData ( object  t)
virtual

Applies the save data.

Parameters
tT.

◆ CleanUp()

void PlatformerPro.Inventory.CleanUp ( )

Combines stacks until stack max is reached and then shifts positions of items such that there are no gaps in the inventory.

◆ CleanUpGaps()

void PlatformerPro.Inventory.CleanUpGaps ( )

Shifts positions of items such that there are no gaps in the inventory.

◆ Consume()

int PlatformerPro.Inventory.Consume ( string  itemId,
int  amount 
)

Consume the item with specified key in the given amount.

Returns
The actual number consumed.
Parameters
keyKey.
amountAmount.

◆ GetFirstSlotForItem()

int PlatformerPro.Inventory.GetFirstSlotForItem ( string  itemId)

Gets the first slot holding the given item.

Returns
The first slot for item.
Parameters
itemIdItem identifier.

◆ GetItemAt()

ItemInstanceData PlatformerPro.Inventory.GetItemAt ( int  position)

Gets item type and amount at the given position or null if nothing there (or out of range).

Returns
The PlatformerPro.ItemInstanceData.
Parameters
positionPosition.

◆ GetItemTypeDataAt()

ItemTypeData PlatformerPro.Inventory.GetItemTypeDataAt ( int  position)

Gets the item type data for the item at the given position or null if nothing there (or out of range).

Returns
The PlatformerPro.ItemInstanceData.
Parameters
positionPosition.

◆ Init()

virtual void PlatformerPro.Inventory.Init ( Character  character)
virtual

Init this instance. Called from awake.

Implements PlatformerPro.ICoreComponent.

◆ ItemCount() [1/2]

virtual int PlatformerPro.Inventory.ItemCount ( ItemTypeData  type)
virtual

Gets the number of items of the given type.

Returns
The count.
Parameters
typeItem type data.

◆ ItemCount() [2/2]

virtual int PlatformerPro.Inventory.ItemCount ( string  itemType)
virtual

Gets the number of items of the given type.

Returns
The count.
Parameters
itemTypeItem type.

◆ PostInit()

virtual void PlatformerPro.Inventory.PostInit ( )
protectedvirtual

Post Init this instance. Called from Start.

◆ RemoveItemAt()

void PlatformerPro.Inventory.RemoveItemAt ( int  index,
int  amount 
)

Remove a single item from the given inventory slot.

Parameters
indexIndex.

◆ SwitchPositions()

void PlatformerPro.Inventory.SwitchPositions ( int  indexA,
int  indexB 
)

Switches the positions of items unless item is a stack of same type it which case it tries to merge the stacks.

Parameters
indexAIndex a.
indexBIndex b.

Member Data Documentation

◆ character

Character PlatformerPro.Inventory.character
protected

Which character does this inventory belong to.

◆ inventoryData

InventoryData PlatformerPro.Inventory.inventoryData
protected

The inventory data.

◆ inventorySize

int PlatformerPro.Inventory.inventorySize

Starting size of the inventory.

◆ loaded

bool PlatformerPro.Inventory.loaded
protected

Tracks if we have loaded data.

◆ noGaps

bool PlatformerPro.Inventory.noGaps

If true empty inventory spots will cause the inventory to be shifted such as there is no gaps.

Property Documentation

◆ AllItems

ItemInstanceData [] PlatformerPro.Inventory.AllItems
get

Gets all inventory item data. WARNING: For performance reasons this is not a copy.

◆ SaveData

virtual object PlatformerPro.Inventory.SaveData
get

Gets the data required to save this inventory.

The save data.


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