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

Stores details about the items a character has collected. Should be on the same Game Object as the character. More...

Inheritance diagram for PlatformerPro.ItemManager:
PlatformerPro.ItemStatProvider PlatformerPro.ICoreComponent PlatformerPro.Persistable PlatformerPro.PlatformerProMonoBehaviour PlatformerPro.ICharacterReference

Public Member Functions

virtual void OnInventoryChanged ()
 Raises the inventory rearranged event. More...
 
virtual void Init (Character character)
 Init with the specified character. More...
 
virtual int CollectItem (Item item)
 Collect the given item. More...
 
virtual bool DropItemFromInventorySlot (int index)
 Drops the item in slot. More...
 
virtual void ApplyItemEffects (string typeId)
 Applies the item effects for the item with given id. More...
 
virtual void ApplyItemEffects (ItemTypeData itemTypeData)
 Apply effects from item data. More...
 
virtual void RemoveItemEffects (string typeId)
 Removes the item effects for the item with given id. More...
 
virtual void ShowItemPickUpBox (Item item)
 Shows the item pickup box (for when auto pickup is off). More...
 
virtual void HideItemPickUpBox (Item item)
 Hides the item pickup box (for when auto pickup is off). More...
 
virtual void RemoveItemEffects (ItemTypeData itemData)
 Removes the item effects. More...
 
virtual int SetItemCount (string itemType, int amount)
 Sets the item count without raising a collection event. More...
 
virtual int ItemCount (string itemType)
 Gets the number of items of the given type. More...
 
virtual int ItemMax (string itemType)
 Gets the maximum number of items for the given type. More...
 
virtual int ConsumeItem (string itemType, int amount)
 Consumes the given amount of items of type itemType without applying any effects! Does not work for equipped items. More...
 
virtual int ConsumeItemFromInventorySlot (int index)
 Consumes the items in the given inventory slot without applying any effects! More...
 
virtual int UseItem (string itemType, int amount)
 Uses the given amount of items of type itemType applying any effects. More...
 
virtual bool UseItemFromInventorySlot (int index)
 Uses a single item from a specific inventory slot. More...
 
virtual bool DamageItemInEquipmentSlot (string slot, int amount)
 
virtual List< ItemAndCountGetItems ()
 Gets a list of items that the character has. More...
 
virtual bool HasItem (string itemType)
 Returns true if the character has at least one of the given item. More...
 
virtual int CollectItem (string itemId, int amount)
 Handle collecting an item, based on type dta instead ofinstance data. NOTE: You should use instance data wherever possible or else variables like durability will not be tracked. More...
 
virtual int CollectItem (ItemInstanceData data)
 Handle collecting an item. More...
 
override void ApplySaveData (object t)
 Applies the save data to the object. More...
 
override System.Type SavedObjectType ()
 Get the type of object this Persistable saves. More...
 
override void ResetSaveData ()
 Resets the save data back to default. More...
 
override System.Type[] GetExtraTypes ()
 Support complex object serialisation by passing additional types to seralizer. 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 pickUpActionButton = -1
 Which action button to use for pickups, or -1 for autopickup More...
 
ItemPickupBox itemPickupBox
 If we don't automatically pick up Items then this object will be shown when an object can be picked up. More...
 
bool dropAllItemsInStack = true
 Should we drop one item at a time from a stack, or all items in a stack. More...
 
Vector3 dropOffset
 Where does the drop spawn from relative to character. More...
 
Vector2 dropImpulse = new Vector2(0, 1f)
 Should we impart some velocity to an item when dropped? More...
 
bool ignoreZeroValuedMultipliers = true
 If true then we allow zero valued multipliers. Otherwise we ignore them and raise a warning. More...
 
- Public Attributes inherited from PlatformerPro.Persistable
bool usePersistenceDefaults = true
 Should we use the persistence defaults or override with our own values. More...
 
bool enablePersistence = true
 Should we enable persistence. More...
 
bool saveOnAnyChange
 Save whenever this value changes (Note: not supported by all objects). More...
 
PersistenceResetType persistenceType
 When do we reset persistence? More...
 

Static Public Attributes

const string UniqueDataIdentifier = "ItemManagerData"
 The player preference identifier. More...
 
- Static Public Attributes inherited from PlatformerPro.Persistable
const string BasePlayerPrefId = "PP.Persistent."
 The base player preference identifier. More...
 

Protected Member Functions

virtual void OnItemCollected (string type, int amount, Character character)
 Raises the item collected event. More...
 
virtual void OnItemConsumed (string type, int amount, Character character)
 Raises the item consumed event. More...
 
virtual void OnItemDamaged (ItemInstanceData data)
 Raises the item damaged event More...
 
virtual void OnItemDestroyed (ItemInstanceData data)
 Raises the item consumed event. More...
 
virtual void OnItemDepleted (string type, Character character)
 Raises the item depleted event. More...
 
virtual void OnItemDropped (string type, Character character)
 Raises the item dropped event. More...
 
virtual void OnItemMaxUpdated (string type, int amount, Character character)
 Raises the item max updated event. More...
 
virtual void SpawnDroppedItem (ItemInstanceData itemInstanceData, int amountToDrop)
 Spawns a dropped item in the scene at Character position. More...
 
virtual bool DoUseItem (ItemTypeData itemTypeData, int amount)
 Uses the given item, but does not handle removing it from stack/inventory. More...
 
override void RecalculateEffectsOfItems ()
 Updates item multiplier stats. More...
 
- Protected Member Functions inherited from PlatformerPro.Persistable
virtual void OnLoaded ()
 Raises the loaded event. More...
 
virtual void ConfigureEventListeners ()
 Init this instance. More...
 
virtual void DoPendingSaves (object sender, PersistenceEventArgs e)
 Trigger any pending saves. More...
 
virtual void PhaseChange (object sender, GamePhaseEventArgs e)
 Handle a change of game phase, look for persistence event and apply. More...
 
virtual void HandleRespawn (object sender, CharacterEventArgs e)
 Handle a change of game phase, look for persistence event and apply. More...
 
virtual void HandleWillExitScene (object sender, SceneEventArgs e)
 Handles the will exit scene event More...
 
virtual void HandleGameOver (object sender, CharacterEventArgs e)
 Handles the game over event More...
 
virtual void HandleDied (object sender, DamageInfoEventArgs e)
 Handles the died event. More...
 

Protected Attributes

Character character
 The character this item manager applies to. More...
 
List< ItemTypeDataitemTypeData
 Data about available item types. More...
 
ItemData itemData
 The item data. More...
 
bool recalculateEffectsOfItems
 Should we recalculate the effects of items this frame? More...
 
- Protected Attributes inherited from PlatformerPro.ItemStatProvider
float totalJumpHeightMultiplier = 1.0f
 
float totalMoveSpeedMultiplier = 1.0f
 
float totalRunSpeedMultiplier = 1.0f
 
float totalAccelerationMultiplier = 1.0f
 
int totalMaxHealthAdjustment = 1
 
float totalDamageMultiplier = 1.0f
 
float totalWeaponSpeedMultiplier = 1.0f
 
- Protected Attributes inherited from PlatformerPro.Persistable
bool loaded
 Have we loaded the data yet? More...
 
bool readyToSave
 Are we ready to save on the next save tick? More...
 
Persistable latestSaveData
 Data to save when we trigger the next save tick. More...
 

Properties

override string Header [get]
 
override Character Character [get, set]
 Gets the character reference. More...
 
override object? SaveData [get]
 Gets the data to save. More...
 
override string Identifier [get]
 Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name). More...
 
- Properties inherited from PlatformerPro.ItemStatProvider
virtual float TotalJumpHeightMultiplier [get]
 Gets the total JumpHeightMultiplier of all equipped items, updated whenever items are equipped. More...
 
virtual float TotalMoveSpeedMultiplier [get]
 Gets the total MoveSpeedMultiplier of all equipped items, updated whenever items are equipped. More...
 
virtual float TotalRunSpeedMultiplier [get]
 Gets the total RunSpeedMultiplier of all equipped items, updated whenever items are equipped. More...
 
virtual float TotalAccelerationMultiplier [get]
 Gets the total AccelerationMultiplier of all equipped items, updated whenever items are equipped. More...
 
virtual int TotalMaxHealthAdjustment [get]
 Gets the total MaxHealthAdjustment of all equipped items, updated whenever items are equipped. More...
 
virtual float TotalDamageMultiplier [get]
 Gets the total DamageMultiplier of all equipped items, updated whenever items are equipped. More...
 
virtual float TotalWeaponSpeedMultiplier [get]
 Gets the total WeaponSpeedMultiplier of all equipped items, updated whenever items are equipped. More...
 
- Properties inherited from PlatformerPro.Persistable
virtual string PlayerPrefsIdentifier [get]
 The player preference identifier. More...
 
virtual bool EnablePersistence [get]
 Gets the value for persistence type taking in to account defaults. More...
 
virtual PersistenceResetType PersistenceType [get]
 Gets the value for persistence type taking in to account defaults. More...
 
virtual bool SaveOnChange [get]
 Gets the value for save on change type taking in to account defaults. More...
 
abstract Character Character [get, set]
 Gets the character. More...
 
abstract object SaveData [get]
 Gets the data to save. More...
 
abstract string Identifier [get]
 Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name). 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...
 
- Properties inherited from PlatformerPro.ICharacterReference
Character Character [get, set]
 Get the character. More...
 

Events

System.EventHandler< ItemEventArgsItemCollected
 Item collected. More...
 
System.EventHandler< ItemEventArgsItemConsumed
 Item consumed. More...
 
System.EventHandler< ItemEventArgsItemDamaged
 Occurs when item damaged. More...
 
System.EventHandler< ItemEventArgsItemDestroyed
 Occurs when item damaged. More...
 
System.EventHandler< ItemEventArgsItemDepleted
 Sent when item is consumed and none remain. More...
 
System.EventHandler< ItemEventArgsItemDropped
 Sent when item is dropped. More...
 
System.EventHandler< ItemEventArgsItemMaxUpdated
 Item collected. More...
 
System.EventHandler< CharacterEventArgsInventoryChanged
 Called when inventory items are changed without neccessarily updating item counts (for example rearranging). More...
 
- Events inherited from PlatformerPro.Persistable
System.EventHandler< EmptyEventArgsLoaded
 Sent when this persistable is loaded. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from PlatformerPro.Persistable
static void Save (Persistable p)
 Save the given persistable. More...
 
static void SaveXml (Persistable p)
 Save the given persistable in XML format. More...
 
static void SaveBinary (Persistable p)
 Save the given persistable in XML format. More...
 
static void Load (Persistable p)
 Load the given persistable. More...
 
static void Reset (Persistable p)
 Resets the given persistable. More...
 
- Static Protected Member Functions inherited from PlatformerPro.Persistable
static object LoadSavedDataXml (Persistable p)
 Does the actual load and returns raw object. More...
 
static object LoadSavedDataBinary (Persistable p)
 Does the actual load and returns raw object. More...
 

Detailed Description

Stores details about the items a character has collected. Should be on the same Game Object as the character.

Member Function Documentation

◆ ApplyItemEffects() [1/2]

virtual void PlatformerPro.ItemManager.ApplyItemEffects ( ItemTypeData  itemTypeData)
virtual

Apply effects from item data.

Parameters
itemDataItem data.

◆ ApplyItemEffects() [2/2]

virtual void PlatformerPro.ItemManager.ApplyItemEffects ( string  typeId)
virtual

Applies the item effects for the item with given id.

Parameters
typeIdType identifier.

◆ ApplySaveData()

override void PlatformerPro.ItemManager.ApplySaveData ( object  t)
virtual

Applies the save data to the object.

Implements PlatformerPro.Persistable.

◆ CollectItem() [1/3]

virtual int PlatformerPro.ItemManager.CollectItem ( Item  item)
virtual

Collect the given item.

Returns
The actual number collected.
Parameters
itemItem.

◆ CollectItem() [2/3]

virtual int PlatformerPro.ItemManager.CollectItem ( ItemInstanceData  data)
virtual

Handle collecting an item.

Returns
The actual number collected (taking in to account max items).
Parameters
dataItem instance data, including amount, etc.

◆ CollectItem() [3/3]

virtual int PlatformerPro.ItemManager.CollectItem ( string  itemId,
int  amount 
)
virtual

Handle collecting an item, based on type dta instead ofinstance data. NOTE: You should use instance data wherever possible or else variables like durability will not be tracked.

Returns
The actual number collected (taking in to account max items).
Parameters
itemIdId oif the itme to add

◆ ConsumeItem()

virtual int PlatformerPro.ItemManager.ConsumeItem ( string  itemType,
int  amount 
)
virtual

Consumes the given amount of items of type itemType without applying any effects! Does not work for equipped items.

Parameters
itemTypeItem type.
amountAmount to consume.
Returns
The actual amount consumed.

◆ ConsumeItemFromInventorySlot()

virtual int PlatformerPro.ItemManager.ConsumeItemFromInventorySlot ( int  index)
virtual

Consumes the items in the given inventory slot without applying any effects!

Parameters
indexInventory slot.
Returns
The actual amount consumed.

◆ DamageItemInEquipmentSlot()

virtual bool PlatformerPro.ItemManager.DamageItemInEquipmentSlot ( string  slot,
int  amount 
)
virtual

◆ DoUseItem()

virtual bool PlatformerPro.ItemManager.DoUseItem ( ItemTypeData  itemTypeData,
int  amount 
)
protectedvirtual

Uses the given item, but does not handle removing it from stack/inventory.

Returns
true, if item can be used, false otherwise false.
Parameters
itemTypeDataItem type data.

◆ DropItemFromInventorySlot()

virtual bool PlatformerPro.ItemManager.DropItemFromInventorySlot ( int  index)
virtual

Drops the item in slot.

Returns
True if dropped or false otherwise.
Parameters
indexslot index.

◆ GetExtraTypes()

override System.Type [] PlatformerPro.ItemManager.GetExtraTypes ( )
virtual

Support complex object serialisation by passing additional types to seralizer.

Reimplemented from PlatformerPro.Persistable.

◆ GetItems()

virtual List<ItemAndCount> PlatformerPro.ItemManager.GetItems ( )
virtual

Gets a list of items that the character has.

Returns
The items the character has.

///

◆ HasItem()

virtual bool PlatformerPro.ItemManager.HasItem ( string  itemType)
virtual

Returns true if the character has at least one of the given item.

Parameters
itemTypeItem type.
Returns
True if the character has the item, false otherwise.

◆ HideItemPickUpBox()

virtual void PlatformerPro.ItemManager.HideItemPickUpBox ( Item  item)
virtual

Hides the item pickup box (for when auto pickup is off).

◆ Init()

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

Init with the specified character.

Parameters
characterCharacter.

Implements PlatformerPro.ICoreComponent.

◆ ItemCount()

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

Gets the number of items of the given type.

Returns
The count.
Parameters
itemTypeItem type.

◆ ItemMax()

virtual int PlatformerPro.ItemManager.ItemMax ( string  itemType)
virtual

Gets the maximum number of items for the given type.

Returns
The count.
Parameters
itemTypeItem type.

◆ OnInventoryChanged()

virtual void PlatformerPro.ItemManager.OnInventoryChanged ( )
virtual

Raises the inventory rearranged event.

◆ OnItemCollected()

virtual void PlatformerPro.ItemManager.OnItemCollected ( string  type,
int  amount,
Character  character 
)
protectedvirtual

Raises the item collected event.

Parameters
typeType.
amountNumber collected.
characterCharacter.

◆ OnItemConsumed()

virtual void PlatformerPro.ItemManager.OnItemConsumed ( string  type,
int  amount,
Character  character 
)
protectedvirtual

Raises the item consumed event.

Parameters
typeType.
amountNumber consumed.
characterCharacter.

◆ OnItemDamaged()

virtual void PlatformerPro.ItemManager.OnItemDamaged ( ItemInstanceData  data)
protectedvirtual

Raises the item damaged event

Parameters
dataItem Data.

◆ OnItemDepleted()

virtual void PlatformerPro.ItemManager.OnItemDepleted ( string  type,
Character  character 
)
protectedvirtual

Raises the item depleted event.

Parameters
typeType.
characterCharacter.

◆ OnItemDestroyed()

virtual void PlatformerPro.ItemManager.OnItemDestroyed ( ItemInstanceData  data)
protectedvirtual

Raises the item consumed event.

Parameters
dataItem data.

◆ OnItemDropped()

virtual void PlatformerPro.ItemManager.OnItemDropped ( string  type,
Character  character 
)
protectedvirtual

Raises the item dropped event.

Parameters
typeType.
characterCharacter.

◆ OnItemMaxUpdated()

virtual void PlatformerPro.ItemManager.OnItemMaxUpdated ( string  type,
int  amount,
Character  character 
)
protectedvirtual

Raises the item max updated event.

Parameters
itemClassItem class.
typeType.
amountAmount.
characterCharacter.

◆ RecalculateEffectsOfItems()

override void PlatformerPro.ItemManager.RecalculateEffectsOfItems ( )
protectedvirtual

Updates item multiplier stats.

Implements PlatformerPro.ItemStatProvider.

◆ RemoveItemEffects() [1/2]

virtual void PlatformerPro.ItemManager.RemoveItemEffects ( ItemTypeData  itemData)
virtual

Removes the item effects.

Parameters
itemDataItem data.

◆ RemoveItemEffects() [2/2]

virtual void PlatformerPro.ItemManager.RemoveItemEffects ( string  typeId)
virtual

Removes the item effects for the item with given id.

Parameters
typeIdType identifier.

◆ ResetSaveData()

override void PlatformerPro.ItemManager.ResetSaveData ( )
virtual

Resets the save data back to default.

Implements PlatformerPro.Persistable.

◆ SavedObjectType()

override System.Type PlatformerPro.ItemManager.SavedObjectType ( )
virtual

Get the type of object this Persistable saves.

Implements PlatformerPro.Persistable.

◆ SetItemCount()

virtual int PlatformerPro.ItemManager.SetItemCount ( string  itemType,
int  amount 
)
virtual

Sets the item count without raising a collection event.

Returns
The item count.
Parameters
itemTypeItem type.
amountItem count.

◆ ShowItemPickUpBox()

virtual void PlatformerPro.ItemManager.ShowItemPickUpBox ( Item  item)
virtual

Shows the item pickup box (for when auto pickup is off).

Parameters
item

◆ SpawnDroppedItem()

virtual void PlatformerPro.ItemManager.SpawnDroppedItem ( ItemInstanceData  itemInstanceData,
int  amountToDrop 
)
protectedvirtual

Spawns a dropped item in the scene at Character position.

Parameters
itemTypeDataItem type data.
amountToDropHow many items appear in the dropped stack.

◆ UseItem()

virtual int PlatformerPro.ItemManager.UseItem ( string  itemType,
int  amount 
)
virtual

Uses the given amount of items of type itemType applying any effects.

Parameters
itemTypeItem type.
amountAmount to consume.
Returns
The actual amount consumed.

◆ UseItemFromInventorySlot()

virtual bool PlatformerPro.ItemManager.UseItemFromInventorySlot ( int  index)
virtual

Uses a single item from a specific inventory slot.

Returns
true, if item from inventory slot was used, false otherwise.
Parameters
indexIndex.

Member Data Documentation

◆ character

Character PlatformerPro.ItemManager.character
protected

The character this item manager applies to.

◆ dropAllItemsInStack

bool PlatformerPro.ItemManager.dropAllItemsInStack = true

Should we drop one item at a time from a stack, or all items in a stack.

◆ dropImpulse

Vector2 PlatformerPro.ItemManager.dropImpulse = new Vector2(0, 1f)

Should we impart some velocity to an item when dropped?

◆ dropOffset

Vector3 PlatformerPro.ItemManager.dropOffset

Where does the drop spawn from relative to character.

◆ ignoreZeroValuedMultipliers

bool PlatformerPro.ItemManager.ignoreZeroValuedMultipliers = true

If true then we allow zero valued multipliers. Otherwise we ignore them and raise a warning.

◆ itemData

ItemData PlatformerPro.ItemManager.itemData
protected

The item data.

◆ itemPickupBox

ItemPickupBox PlatformerPro.ItemManager.itemPickupBox

If we don't automatically pick up Items then this object will be shown when an object can be picked up.

◆ itemTypeData

List<ItemTypeData> PlatformerPro.ItemManager.itemTypeData
protected

Data about available item types.

◆ pickUpActionButton

int PlatformerPro.ItemManager.pickUpActionButton = -1

Which action button to use for pickups, or -1 for autopickup

◆ recalculateEffectsOfItems

bool PlatformerPro.ItemManager.recalculateEffectsOfItems
protected

Should we recalculate the effects of items this frame?

◆ UniqueDataIdentifier

const string PlatformerPro.ItemManager.UniqueDataIdentifier = "ItemManagerData"
static

The player preference identifier.

Property Documentation

◆ Character

override Character PlatformerPro.ItemManager.Character
getset

Gets the character reference.

The character.

◆ Header

override string PlatformerPro.ItemManager.Header
get

◆ Identifier

override string PlatformerPro.ItemManager.Identifier
get

Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name).

The identifier.

◆ SaveData

override object? PlatformerPro.ItemManager.SaveData
get

Gets the data to save.

Event Documentation

◆ InventoryChanged

System.EventHandler<CharacterEventArgs> PlatformerPro.ItemManager.InventoryChanged

Called when inventory items are changed without neccessarily updating item counts (for example rearranging).

◆ ItemCollected

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemCollected

Item collected.

◆ ItemConsumed

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemConsumed

Item consumed.

◆ ItemDamaged

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemDamaged

Occurs when item damaged.

◆ ItemDepleted

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemDepleted

Sent when item is consumed and none remain.

◆ ItemDestroyed

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemDestroyed

Occurs when item damaged.

◆ ItemDropped

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemDropped

Sent when item is dropped.

◆ ItemMaxUpdated

System.EventHandler<ItemEventArgs> PlatformerPro.ItemManager.ItemMaxUpdated

Item collected.


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