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

Enemy AI which is driven by a user defined behaviour graph. More...

Inheritance diagram for PlatformerPro.EnemyAI_AIGraph:
PlatformerPro.EnemyAI PlatformerPro.PlatformerProMonoBehaviour

Public Member Functions

override void Init (Enemy enemy)
 Init this enemy AI. More...
 
override EnemyState Decide ()
 Decide the next move More...
 
override bool Sense ()
 Sense the character. More...
 
override DamageInfo DoDamage (DamageInfo info)
 Handle damage. More...
 
override void StateTransitioned ()
 Called to tell the AI that we were able to handle the desired state. More...
 
override void StateNotTransitioned ()
 Called to tell the AI that we were not able to handle the desired state. Usually due to a movement that wont release control. More...
 
void ResetHitCounter ()
 Reset the number of hits counter to 0. More...
 
override void Message (string message)
 Handle a message sent to the enemy. More...
 
- Public Member Functions inherited from PlatformerPro.EnemyAI
virtual bool UpdateTimer ()
 Update the timer by frame time, we drive this externally so we can halt the mob from a single place (the Enemy script). 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

List< EnemyNamedAIGraphsgraphs
 The graphs to use to control the enemies behaviour. The first entry is the starting phase. More...
 
float maxTargetDistance
 Distance at which the target is "lost". More...
 
bool alwaysFaceTarget
 If true we always face the target if we have one. More...
 
float faceTargetLeeway = 0.25f
 Leeway required before we change facing direction when facing target. More...
 
float sightDistance = 5.0f
 How far can the enemy see? More...
 
float sightYOffset
 Y position of the characters 'eyes'. More...
 
LayerMask sightLayers
 Layers to check for obstacle and characters. More...
 
float hearingRadius = 1.0f
 Range of the proximity sense. More...
 
Vector2 hearingOffset
 Centre point of the proximity sense. More...
 
LayerMask hearingLayers
 Layers to check for proximity sense. More...
 
- Public Attributes inherited from PlatformerPro.EnemyAI
float decisionInterval
 How long between decisions, increasing this improves performance but makes the enemy less responsive. More...
 

Protected Member Functions

virtual void DoUpdate ()
 Run each frame to determine and execute move. More...
 
virtual void UpdateTimers ()
 Check the timer interrupts to see if any should fire. More...
 
virtual void HandleEnemyDamaged (object sender, DamageInfoEventArgs e)
 Handle the enemy getting damaged. More...
 
virtual void HandleMoveCompleted (object sender, EventArgs e)
 Handle the enemy movement completing. More...
 
virtual void SwitchPhase (EnemyAIGraph graph)
 Find the entry point of the graph and set up the first action. More...
 
virtual void ProcessCurrentNode ()
 Check each state in the graph to determine if it should exit and if so update the current movement. More...
 
virtual bool HandleExit (IProcessableEnemyNode node, int option)
 Handle moving through node exit to a new state. Includes calling any actions on the node. More...
 
virtual void HandleActions (IProcessableEnemyNode node, int option)
 Do the actions associated with node exit. More...
 
virtual void HandleActions (List< NodePort > connections)
 Do the actions associated with node exit. More...
 
virtual bool CheckForExit (OptionWithCondition exit)
 Checks a specific exit condition to see if its conditions have been met and returns true if they have. More...
 
virtual void ResetState ()
 
virtual void ResetPhase ()
 
virtual bool CheckForCharacter ()
 
virtual bool See ()
 Look for a character. More...
 
virtual bool Hear ()
 Listen for a character. More...
 

Protected Attributes

EnemyNode currentNode
 Where are we in the enemy graph? More...
 
bool hasRunCheckForCharacter
 Track if we have run the check for player call so we don't eat resources by running it more than once a frame. More...
 
bool checkForCharacterResult
 Result of the last check for character. More...
 
float stateTimer
 Stores how long we have been in current state. If the same state is played multiple times this tracks the time in the CURRENT iteration. More...
 
float graphTimer
 Stores how long we have been in current state. If the same state is played multiple times this tracks the time in the CURRENT iteration. More...
 
bool stateMovementComplete
 Stores the completion state of current move. More...
 
int hitCount
 Stores the number of times we have been damaged while in current state. More...
 
Transform myTransform
 Cached transform reference. More...
 
Collider2D[] proximityColliders
 Used to store results of hearing overlap call. More...
 
EnemyInterruptDamagedNode damageInterrupt
 Cached reference to the damage handler. More...
 
EnemyInterruptCounter[] counterInterrupts
 Cached reference to the counter handlers. More...
 
EnemyInterruptTimer[] timerInterrupts
 Cached reference to the timer handlers. More...
 
EnemyInterruptHealth[] healthInterrupts
 Cached reference to the health interrupt handlers. More...
 
EnemyInterruptEnemyMessage[] messageInterrupts
 Cached reference to the message interrupt handlers. More...
 
float[] timers
 Timers for each timer handler. More...
 
bool locked
 If the AI is locked we can't change state. Generally used to wait for a movement to complete. More...
 
Dictionary< string, EnemyAIGraphgraphLookup
 Associated graph name to graph. More...
 
EnemyAIGraph currentGraph
 Currently active graph More...
 
bool hasTransitionedThisFrame
 Track if anything has already made us transition this frame. If so we can't transition again. More...
 
bool hasHadInterruptThisFrame
 Track if an interrupt has already made us transition this frame. If so we can't transition again. More...
 
bool hasDecided
 Track if we have run our decision logic already. If so we wont run it again. Instead just return the current state. More...
 
int counter
 A generic counter you can use to control loops etc. More...
 
- Protected Attributes inherited from PlatformerPro.EnemyAI
float decisionTimer
 Timer for tracking decision interval. More...
 
Enemy enemy
 Enemy reference. More...
 

Properties

override string Header [get]
 
virtual int Counter [get, set]
 
- Properties inherited from PlatformerPro.EnemyAI
virtual string ExtraSaveData [get, set]
 If we are going to save the enemy, this data will be saved if save state is enabled. 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

Enemy AI which is driven by a user defined behaviour graph.

Member Function Documentation

◆ CheckForCharacter()

virtual bool PlatformerPro.EnemyAI_AIGraph.CheckForCharacter ( )
protectedvirtual

Try to find a character by looking and listening.

Returns
true, if for character was checked, false otherwise.

◆ CheckForExit()

virtual bool PlatformerPro.EnemyAI_AIGraph.CheckForExit ( OptionWithCondition  exit)
protectedvirtual

Checks a specific exit condition to see if its conditions have been met and returns true if they have.

◆ Decide()

override EnemyState PlatformerPro.EnemyAI_AIGraph.Decide ( )
virtual

Decide the next move

Reimplemented from PlatformerPro.EnemyAI.

◆ DoDamage()

override DamageInfo PlatformerPro.EnemyAI_AIGraph.DoDamage ( DamageInfo  info)
virtual

Handle damage.

Parameters
infoDamage details
Returns
The updated damage info.

Reimplemented from PlatformerPro.EnemyAI.

◆ DoUpdate()

virtual void PlatformerPro.EnemyAI_AIGraph.DoUpdate ( )
protectedvirtual

Run each frame to determine and execute move.

◆ HandleActions() [1/2]

virtual void PlatformerPro.EnemyAI_AIGraph.HandleActions ( IProcessableEnemyNode  node,
int  option 
)
protectedvirtual

Do the actions associated with node exit.

Parameters
connections

◆ HandleActions() [2/2]

virtual void PlatformerPro.EnemyAI_AIGraph.HandleActions ( List< NodePort connections)
protectedvirtual

Do the actions associated with node exit.

Parameters
connections

◆ HandleEnemyDamaged()

virtual void PlatformerPro.EnemyAI_AIGraph.HandleEnemyDamaged ( object  sender,
DamageInfoEventArgs  e 
)
protectedvirtual

Handle the enemy getting damaged.

◆ HandleExit()

virtual bool PlatformerPro.EnemyAI_AIGraph.HandleExit ( IProcessableEnemyNode  node,
int  option 
)
protectedvirtual

Handle moving through node exit to a new state. Includes calling any actions on the node.

Parameters
nodeCurrent node
optionOption position
Returns
true if the state changed, false otherwise

◆ HandleMoveCompleted()

virtual void PlatformerPro.EnemyAI_AIGraph.HandleMoveCompleted ( object  sender,
EventArgs  e 
)
protectedvirtual

Handle the enemy movement completing.

◆ Hear()

virtual bool PlatformerPro.EnemyAI_AIGraph.Hear ( )
protectedvirtual

Listen for a character.

◆ Init()

override void PlatformerPro.EnemyAI_AIGraph.Init ( Enemy  enemy)
virtual

Init this enemy AI.

Parameters
enemyEnemy we are the brain for.

Reimplemented from PlatformerPro.EnemyAI.

◆ Message()

override void PlatformerPro.EnemyAI_AIGraph.Message ( string  message)
virtual

Handle a message sent to the enemy.

Parameters
message

Reimplemented from PlatformerPro.EnemyAI.

◆ ProcessCurrentNode()

virtual void PlatformerPro.EnemyAI_AIGraph.ProcessCurrentNode ( )
protectedvirtual

Check each state in the graph to determine if it should exit and if so update the current movement.

◆ ResetHitCounter()

void PlatformerPro.EnemyAI_AIGraph.ResetHitCounter ( )

Reset the number of hits counter to 0.

◆ ResetPhase()

virtual void PlatformerPro.EnemyAI_AIGraph.ResetPhase ( )
protectedvirtual

◆ ResetState()

virtual void PlatformerPro.EnemyAI_AIGraph.ResetState ( )
protectedvirtual

◆ See()

virtual bool PlatformerPro.EnemyAI_AIGraph.See ( )
protectedvirtual

Look for a character.

◆ Sense()

override bool PlatformerPro.EnemyAI_AIGraph.Sense ( )
virtual

Sense the character.

Reimplemented from PlatformerPro.EnemyAI.

◆ StateNotTransitioned()

override void PlatformerPro.EnemyAI_AIGraph.StateNotTransitioned ( )
virtual

Called to tell the AI that we were not able to handle the desired state. Usually due to a movement that wont release control.

Reimplemented from PlatformerPro.EnemyAI.

◆ StateTransitioned()

override void PlatformerPro.EnemyAI_AIGraph.StateTransitioned ( )
virtual

Called to tell the AI that we were able to handle the desired state.

Reimplemented from PlatformerPro.EnemyAI.

◆ SwitchPhase()

virtual void PlatformerPro.EnemyAI_AIGraph.SwitchPhase ( EnemyAIGraph  graph)
protectedvirtual

Find the entry point of the graph and set up the first action.

◆ UpdateTimers()

virtual void PlatformerPro.EnemyAI_AIGraph.UpdateTimers ( )
protectedvirtual

Check the timer interrupts to see if any should fire.

Member Data Documentation

◆ alwaysFaceTarget

bool PlatformerPro.EnemyAI_AIGraph.alwaysFaceTarget

If true we always face the target if we have one.

◆ checkForCharacterResult

bool PlatformerPro.EnemyAI_AIGraph.checkForCharacterResult
protected

Result of the last check for character.

◆ counter

int PlatformerPro.EnemyAI_AIGraph.counter
protected

A generic counter you can use to control loops etc.

◆ counterInterrupts

EnemyInterruptCounter [] PlatformerPro.EnemyAI_AIGraph.counterInterrupts
protected

Cached reference to the counter handlers.

◆ currentGraph

EnemyAIGraph PlatformerPro.EnemyAI_AIGraph.currentGraph
protected

Currently active graph

◆ currentNode

EnemyNode PlatformerPro.EnemyAI_AIGraph.currentNode
protected

Where are we in the enemy graph?

◆ damageInterrupt

EnemyInterruptDamagedNode PlatformerPro.EnemyAI_AIGraph.damageInterrupt
protected

Cached reference to the damage handler.

◆ faceTargetLeeway

float PlatformerPro.EnemyAI_AIGraph.faceTargetLeeway = 0.25f

Leeway required before we change facing direction when facing target.

◆ graphLookup

Dictionary<string, EnemyAIGraph> PlatformerPro.EnemyAI_AIGraph.graphLookup
protected

Associated graph name to graph.

◆ graphs

List<EnemyNamedAIGraphs> PlatformerPro.EnemyAI_AIGraph.graphs

The graphs to use to control the enemies behaviour. The first entry is the starting phase.

◆ graphTimer

float PlatformerPro.EnemyAI_AIGraph.graphTimer
protected

Stores how long we have been in current state. If the same state is played multiple times this tracks the time in the CURRENT iteration.

◆ hasDecided

bool PlatformerPro.EnemyAI_AIGraph.hasDecided
protected

Track if we have run our decision logic already. If so we wont run it again. Instead just return the current state.

◆ hasHadInterruptThisFrame

bool PlatformerPro.EnemyAI_AIGraph.hasHadInterruptThisFrame
protected

Track if an interrupt has already made us transition this frame. If so we can't transition again.

◆ hasRunCheckForCharacter

bool PlatformerPro.EnemyAI_AIGraph.hasRunCheckForCharacter
protected

Track if we have run the check for player call so we don't eat resources by running it more than once a frame.

◆ hasTransitionedThisFrame

bool PlatformerPro.EnemyAI_AIGraph.hasTransitionedThisFrame
protected

Track if anything has already made us transition this frame. If so we can't transition again.

◆ healthInterrupts

EnemyInterruptHealth [] PlatformerPro.EnemyAI_AIGraph.healthInterrupts
protected

Cached reference to the health interrupt handlers.

◆ hearingLayers

LayerMask PlatformerPro.EnemyAI_AIGraph.hearingLayers

Layers to check for proximity sense.

◆ hearingOffset

Vector2 PlatformerPro.EnemyAI_AIGraph.hearingOffset

Centre point of the proximity sense.

◆ hearingRadius

float PlatformerPro.EnemyAI_AIGraph.hearingRadius = 1.0f

Range of the proximity sense.

◆ hitCount

int PlatformerPro.EnemyAI_AIGraph.hitCount
protected

Stores the number of times we have been damaged while in current state.

◆ locked

bool PlatformerPro.EnemyAI_AIGraph.locked
protected

If the AI is locked we can't change state. Generally used to wait for a movement to complete.

◆ maxTargetDistance

float PlatformerPro.EnemyAI_AIGraph.maxTargetDistance

Distance at which the target is "lost".

◆ messageInterrupts

EnemyInterruptEnemyMessage [] PlatformerPro.EnemyAI_AIGraph.messageInterrupts
protected

Cached reference to the message interrupt handlers.

◆ myTransform

Transform PlatformerPro.EnemyAI_AIGraph.myTransform
protected

Cached transform reference.

◆ proximityColliders

Collider2D [] PlatformerPro.EnemyAI_AIGraph.proximityColliders
protected

Used to store results of hearing overlap call.

◆ sightDistance

float PlatformerPro.EnemyAI_AIGraph.sightDistance = 5.0f

How far can the enemy see?

◆ sightLayers

LayerMask PlatformerPro.EnemyAI_AIGraph.sightLayers

Layers to check for obstacle and characters.

◆ sightYOffset

float PlatformerPro.EnemyAI_AIGraph.sightYOffset

Y position of the characters 'eyes'.

◆ stateMovementComplete

bool PlatformerPro.EnemyAI_AIGraph.stateMovementComplete
protected

Stores the completion state of current move.

◆ stateTimer

float PlatformerPro.EnemyAI_AIGraph.stateTimer
protected

Stores how long we have been in current state. If the same state is played multiple times this tracks the time in the CURRENT iteration.

◆ timerInterrupts

EnemyInterruptTimer [] PlatformerPro.EnemyAI_AIGraph.timerInterrupts
protected

Cached reference to the timer handlers.

◆ timers

float [] PlatformerPro.EnemyAI_AIGraph.timers
protected

Timers for each timer handler.

Property Documentation

◆ Counter

virtual int PlatformerPro.EnemyAI_AIGraph.Counter
getset

◆ Header

override string PlatformerPro.EnemyAI_AIGraph.Header
get

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