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

Tracks character health and triggers character death. More...

Inheritance diagram for PlatformerPro.CharacterHealth:
PlatformerPro.Persistable PlatformerPro.PlatformerProMonoBehaviour PlatformerPro.ICharacterReference

Public Member Functions

virtual void Init (Character character)
 Init with the specified character. More...
 
virtual void ResetHealth ()
 Reset the health back to its starting value More...
 
virtual void Heal (int amount)
 Heal the character by the specified amount. More...
 
virtual void SetInvulnerable (float time)
 Makes the character invulnerable for the specified time. More...
 
virtual void SetInvulnerable ()
 Makes the character invulnerable for the specified time. More...
 
virtual void SetVulnerable ()
 Makes the character invulnerable for the specified time. More...
 
virtual void Damage (int amount)
 Damage the character by the specified amount. More...
 
virtual void Damage (DamageInfo info)
 Damage the character with the specified damage information. This is the preferred method of receiving damage as it allows the hazard and hit direction to be processed (for example you could have immunity or damage reduction for a certain hazard). More...
 
virtual void Kill ()
 Kills the character. More...
 
virtual void Kill (DamageInfo info)
 Kills the character. 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...
 
- Public Member Functions inherited from PlatformerPro.Persistable
virtual 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 startingHealth
 Health the character starts with. More...
 
int maxHealth
 Maximum health of the character. More...
 
int startingLives
 Lives the character starts with. Use 0 for no lives. More...
 
int maxLives
 Maximum lives of the character. More...
 
float invulnerableTime
 How long the character is invulnerable to damage after being hit. More...
 
DamageImmunity[] damageImmunity
 The damage immunity. More...
 
DeathAction[] deathActions
 What do we do on death. More...
 
bool skipDamageAnimationOnDeath
 Should we not play a damage animation if we die (instead we might go straight to death animation). More...
 
bool skipDeathActionsOnGameOver
 Should we do the death actions on game over or go straight to GameOver actions More...
 
bool sendEventsOnZeroDamage
 If true send damage events even when damage amount is zero. More...
 
bool saveHealthBetweenLevels
 If true send damage events even when damage amount is zero. 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 = "CharacterHealth.Lives"
 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 OnHealed (int amount)
 Raises the healed event. More...
 
virtual void OnDamaged (DamageInfo info)
 Raises the damaged event. More...
 
virtual void OnDied (DamageInfo info)
 Raises the died event. More...
 
virtual void OnGameOver ()
 Raises the game over event. More...
 
virtual void OnGainLives (int amount)
 Raises the gain lives event. More...
 
virtual void OnMaxValuesUpdated ()
 Raises the max values updated event. More...
 
override void ConfigureEventListeners ()
 Init this instance. More...
 
virtual void UpdateMaxHealth ()
 
virtual void DoUpdateMaxHealth ()
 
virtual void DoDeath (DamageInfo info)
 Do the death actions More...
 
virtual void DoGameOver (DamageInfo info)
 End the game More...
 
override void PhaseChange (object sender, GamePhaseEventArgs e)
 Handle a change of game phase, look for persistence event and apply. More...
 
virtual IEnumerator DoDeathAction (DeathAction action, DamageInfo info)
 Does a death action. More...
 
- Protected Member Functions inherited from PlatformerPro.Persistable
virtual void OnLoaded ()
 Raises the loaded event. More...
 
virtual void DoPendingSaves (object sender, PersistenceEventArgs e)
 Trigger any pending saves. 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

int health
 Characters current health. More...
 
int lives
 Characters current lives. More...
 
float invulnerableTimer
 Timer for invulnerability. Character is invulnerable when this is greater than zero. More...
 
Character character
 Cached Character reference More...
 
bool dying
 If we are dying ignore damage messages. More...
 
DamageInfoEventArgs damageEventArgs
 Cached copy of damage event args to save on allocations. More...
 
bool updateMaxHealthThisFrame
 Checks if we have calculated max health this frame. We only do this once per frame. More...
 
int lastCalculatedMaxHealth
 Tracks value of last calculated max health which includes More...
 
- 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 Character Character [get, set]
 Gets the character reference. More...
 
virtual bool IsInvulnerable [get]
 Is the character currently invulnerable? More...
 
virtual int? CurrentHealth [get, set]
 Gets the current health More...
 
virtual int MaxHealth [get, set]
 Gets or sets the max health More...
 
virtual int MaxLives [get, set]
 Gets or sets the max lives More...
 
virtual float CurrentHealthAsPercentage [get]
 Gets a value representing the current health as a percentage between 0 (none) and 1 (full). More...
 
virtual int CurrentLives [get, set]
 Gets the current number of lives. 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.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< HealedEventArgsHealed
 Event for health gain. More...
 
System.EventHandler< DamageInfoEventArgsDamaged
 Event for damage. More...
 
System.EventHandler< DamageInfoEventArgsDied
 Event for death. More...
 
System.EventHandler< CharacterEventArgsGameOver
 Event for game over. More...
 
System.EventHandler< HealedEventArgsGainLives
 Event for health gain. More...
 
System.EventHandler< HealedEventArgsMaxValuesUpdated
 Event for when max lives or health changes. 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

Tracks character health and triggers character death.

Member Function Documentation

◆ ApplySaveData()

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

Applies the save data to the object.

Implements PlatformerPro.Persistable.

◆ ConfigureEventListeners()

override void PlatformerPro.CharacterHealth.ConfigureEventListeners ( )
protectedvirtual

Init this instance.

Reimplemented from PlatformerPro.Persistable.

◆ Damage() [1/2]

virtual void PlatformerPro.CharacterHealth.Damage ( DamageInfo  info)
virtual

Damage the character with the specified damage information. This is the preferred method of receiving damage as it allows the hazard and hit direction to be processed (for example you could have immunity or damage reduction for a certain hazard).

Parameters
infoThe damage info.

◆ Damage() [2/2]

virtual void PlatformerPro.CharacterHealth.Damage ( int  amount)
virtual

Damage the character by the specified amount.

Parameters
amountAmount.

◆ DoDeath()

virtual void PlatformerPro.CharacterHealth.DoDeath ( DamageInfo  info)
protectedvirtual

Do the death actions

◆ DoDeathAction()

virtual IEnumerator PlatformerPro.CharacterHealth.DoDeathAction ( DeathAction  action,
DamageInfo  info 
)
protectedvirtual

Does a death action.

Parameters
actionAction.

◆ DoGameOver()

virtual void PlatformerPro.CharacterHealth.DoGameOver ( DamageInfo  info)
protectedvirtual

End the game

◆ DoUpdateMaxHealth()

virtual void PlatformerPro.CharacterHealth.DoUpdateMaxHealth ( )
protectedvirtual

◆ Heal()

virtual void PlatformerPro.CharacterHealth.Heal ( int  amount)
virtual

Heal the character by the specified amount.

Parameters
amountAmount.

◆ Init()

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

Init with the specified character.

Parameters
characterCharacter.

◆ Kill() [1/2]

virtual void PlatformerPro.CharacterHealth.Kill ( )
virtual

Kills the character.

◆ Kill() [2/2]

virtual void PlatformerPro.CharacterHealth.Kill ( DamageInfo  info)
virtual

Kills the character.

◆ OnDamaged()

virtual void PlatformerPro.CharacterHealth.OnDamaged ( DamageInfo  info)
protectedvirtual

Raises the damaged event.

Parameters
infoInfo.

◆ OnDied()

virtual void PlatformerPro.CharacterHealth.OnDied ( DamageInfo  info)
protectedvirtual

Raises the died event.

Parameters
infoInfo.

◆ OnGainLives()

virtual void PlatformerPro.CharacterHealth.OnGainLives ( int  amount)
protectedvirtual

Raises the gain lives event.

Parameters
amountAmount.

◆ OnGameOver()

virtual void PlatformerPro.CharacterHealth.OnGameOver ( )
protectedvirtual

Raises the game over event.

Parameters
infoInfo.

◆ OnHealed()

virtual void PlatformerPro.CharacterHealth.OnHealed ( int  amount)
protectedvirtual

Raises the healed event.

Parameters
amountAmount healed.

◆ OnMaxValuesUpdated()

virtual void PlatformerPro.CharacterHealth.OnMaxValuesUpdated ( )
protectedvirtual

Raises the max values updated event.

◆ PhaseChange()

override void PlatformerPro.CharacterHealth.PhaseChange ( object  sender,
GamePhaseEventArgs  e 
)
protectedvirtual

Handle a change of game phase, look for persistence event and apply.

Parameters
senderSender.
eE.

Reimplemented from PlatformerPro.Persistable.

◆ ResetHealth()

virtual void PlatformerPro.CharacterHealth.ResetHealth ( )
virtual

Reset the health back to its starting value

◆ ResetSaveData()

override void PlatformerPro.CharacterHealth.ResetSaveData ( )
virtual

Resets the save data back to default.

Implements PlatformerPro.Persistable.

◆ SavedObjectType()

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

Get the type of object this Persistable saves.

Implements PlatformerPro.Persistable.

◆ SetInvulnerable() [1/2]

virtual void PlatformerPro.CharacterHealth.SetInvulnerable ( )
virtual

Makes the character invulnerable for the specified time.

Parameters
timeHow long the cahracter is unvulnerable for.

◆ SetInvulnerable() [2/2]

virtual void PlatformerPro.CharacterHealth.SetInvulnerable ( float  time)
virtual

Makes the character invulnerable for the specified time.

Parameters
timeHow long the cahracter is unvulnerable for.

◆ SetVulnerable()

virtual void PlatformerPro.CharacterHealth.SetVulnerable ( )
virtual

Makes the character invulnerable for the specified time.

Parameters
timeHow long the cahracter is unvulnerable for.

◆ UpdateMaxHealth()

virtual void PlatformerPro.CharacterHealth.UpdateMaxHealth ( )
protectedvirtual

Member Data Documentation

◆ character

Character PlatformerPro.CharacterHealth.character
protected

Cached Character reference

◆ damageEventArgs

DamageInfoEventArgs PlatformerPro.CharacterHealth.damageEventArgs
protected

Cached copy of damage event args to save on allocations.

◆ damageImmunity

DamageImmunity [] PlatformerPro.CharacterHealth.damageImmunity

The damage immunity.

◆ deathActions

DeathAction [] PlatformerPro.CharacterHealth.deathActions

What do we do on death.

◆ dying

bool PlatformerPro.CharacterHealth.dying
protected

If we are dying ignore damage messages.

◆ health

int PlatformerPro.CharacterHealth.health
protected

Characters current health.

◆ invulnerableTime

float PlatformerPro.CharacterHealth.invulnerableTime

How long the character is invulnerable to damage after being hit.

◆ invulnerableTimer

float PlatformerPro.CharacterHealth.invulnerableTimer
protected

Timer for invulnerability. Character is invulnerable when this is greater than zero.

◆ lastCalculatedMaxHealth

int PlatformerPro.CharacterHealth.lastCalculatedMaxHealth
protected

Tracks value of last calculated max health which includes

◆ lives

int PlatformerPro.CharacterHealth.lives
protected

Characters current lives.

◆ maxHealth

int PlatformerPro.CharacterHealth.maxHealth

Maximum health of the character.

◆ maxLives

int PlatformerPro.CharacterHealth.maxLives

Maximum lives of the character.

◆ saveHealthBetweenLevels

bool PlatformerPro.CharacterHealth.saveHealthBetweenLevels

If true send damage events even when damage amount is zero.

◆ sendEventsOnZeroDamage

bool PlatformerPro.CharacterHealth.sendEventsOnZeroDamage

If true send damage events even when damage amount is zero.

◆ skipDamageAnimationOnDeath

bool PlatformerPro.CharacterHealth.skipDamageAnimationOnDeath

Should we not play a damage animation if we die (instead we might go straight to death animation).

◆ skipDeathActionsOnGameOver

bool PlatformerPro.CharacterHealth.skipDeathActionsOnGameOver

Should we do the death actions on game over or go straight to GameOver actions

◆ startingHealth

int PlatformerPro.CharacterHealth.startingHealth

Health the character starts with.

◆ startingLives

int PlatformerPro.CharacterHealth.startingLives

Lives the character starts with. Use 0 for no lives.

◆ UniqueDataIdentifier

const string PlatformerPro.CharacterHealth.UniqueDataIdentifier = "CharacterHealth.Lives"
static

The player preference identifier.

◆ updateMaxHealthThisFrame

bool PlatformerPro.CharacterHealth.updateMaxHealthThisFrame
protected

Checks if we have calculated max health this frame. We only do this once per frame.

Property Documentation

◆ Character

override Character PlatformerPro.CharacterHealth.Character
getset

Gets the character reference.

The character.

◆ CurrentHealth

virtual int? PlatformerPro.CharacterHealth.CurrentHealth
getset

Gets the current health

◆ CurrentHealthAsPercentage

virtual float PlatformerPro.CharacterHealth.CurrentHealthAsPercentage
get

Gets a value representing the current health as a percentage between 0 (none) and 1 (full).

Returns
The percentage health between 0 and 1.

◆ CurrentLives

virtual int PlatformerPro.CharacterHealth.CurrentLives
getset

Gets the current number of lives.

◆ Identifier

override string PlatformerPro.CharacterHealth.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.

◆ IsInvulnerable

virtual bool PlatformerPro.CharacterHealth.IsInvulnerable
get

Is the character currently invulnerable?

The character.

◆ MaxHealth

virtual int PlatformerPro.CharacterHealth.MaxHealth
getset

Gets or sets the max health

◆ MaxLives

virtual int PlatformerPro.CharacterHealth.MaxLives
getset

Gets or sets the max lives

◆ SaveData

override object PlatformerPro.CharacterHealth.SaveData
get

Gets the data to save.

Event Documentation

◆ Damaged

System.EventHandler<DamageInfoEventArgs> PlatformerPro.CharacterHealth.Damaged

Event for damage.

◆ Died

System.EventHandler<DamageInfoEventArgs> PlatformerPro.CharacterHealth.Died

Event for death.

◆ GainLives

System.EventHandler<HealedEventArgs> PlatformerPro.CharacterHealth.GainLives

Event for health gain.

◆ GameOver

System.EventHandler<CharacterEventArgs> PlatformerPro.CharacterHealth.GameOver

Event for game over.

◆ Healed

System.EventHandler<HealedEventArgs> PlatformerPro.CharacterHealth.Healed

Event for health gain.

◆ MaxValuesUpdated

System.EventHandler<HealedEventArgs> PlatformerPro.CharacterHealth.MaxValuesUpdated

Event for when max lives or health changes.


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