RAIN.Path.PathManager Class Reference

PathManager is both a helper class for building pathfinding within the UnityEditor and a utility class for accessing path-based movement in RAIN. More...

List of all members.

Public Member Functions

 PathManager ()
 Default constructor.
void ReInit (Agent agent)
 ReInit reinitializes the path manager to include any changed public variables, added files, etc.
void CreateMoveLookTargets ()
 Ensure that the moveTarget and lookTarget variables are not null. If they are null, create new objects, otherwise do nothing.
void Awake ()
 Awake is the Unity event handler for component activation.
bool MoveTo (Agent agent, float deltaTime, Vector3 position)
 MoveTo will set the moveTarget to be a Vector target to the specified position, then call Move.
bool Move (Agent agent, float deltaTime)
 Execute the move step - proceeding to the moveTarget based on the current path setup.
bool GetPathToMoveTarget (Agent agent, float deltaTime, out PathBase path)
 Attempt to create a path from the agent to the current moveTarget. This method may work across multiple calls, only performing part of the pathfind during each call.
bool LookAt (Agent agent, float deltaTime, Vector3 position)
 Set the lookTarget to a particular position and then Look at it.
bool Look (Agent agent, float deltaTime)
 Execute the look step - turn to face the looktarget.
void Avoid (Agent agent, float deltaTime)
 Execute the avoid step - perform obstacle avoidance movement. Note that this is called by Move automatically if obstacle avoidance is enabled.
void LoadWaypointGraphFromFile (string filename, bool replaceExistingGraph)
 Set the waypointFilename to the specified filename, then load the graph. If a waypointgraph has already been loaded and replaceExistingGraph is false, this will do nothing The graph will be stored in the shared graph array for sharing with other AI.
void LoadWaypointGraphFromCollection (GameObject collection, bool replaceExistingGraph)
 Load the waypointPathGraph from the named waypoint collection. If a graph is already loaded and replaceExistingGraph is false, this will do nothing.
void LoadNavigationGridGraphFromFile (string filename, bool replaceExistingGraph)
 Load the gridPathGraph from a file. The graph will be stored in the shared graph array for sharing with other AI.
bool SaveWaypointGraph ()
 SaveWaypointGraph saves all waypoints and connections from the WaypointCollection into a waypoint file.
 PathManager ()
 Default constructor.
void ReInit ()
 ReInit reinitializes the path manager to include any changed public variables, added files, etc.
void Awake ()
 Awake is the Unity event handler for component activation.
void OnDrawGizmos ()
 If we are drawing gizmos, attempt to draw the graph wireframe for any loaded recast quad field.
void MoveTo (Agent agent, float deltaTime, Vector3 position)
void LookAt (Agent agent, float deltaTime, Vector3 position)
void Avoid (Agent agent, float deltaTime)
bool SaveWaypointGraph ()
 SaveWaypointGraph saves all waypoints and connections from the WaypointCollection into a waypoint file.
bool LoadQuadFieldPathGraph ()
 Load the quad field path graph defined in the navmeshFilename.
bool SaveQuadFieldGraph ()
 SaveQuadFieldGraph saves a navigation graph associated with the entire level.
void GenerateNavigationGraphForWaypoint (string filename, Waypoint wp)
 GenerateNavigationGraphForWaypoint generates a local navigation mesh between the waypoint and its neighbors.

Static Public Member Functions

static void ClearSharedGraphs ()
 Clear out all shared graphs so that the next request for a path graph will require a reload.
static PathGraph RetrieveGraph (string filename)
 Retrieve a pathgraph based on a filename. Use this method to obtain a shared graph instead of loading a new one.
static void StoreGraph (string filename, PathGraph pg)
 Store a loaded pathgraph for sharing.
static void ReplaceGraph (string filename, PathGraph pg)
 Replace a shared graph with a new one.

Public Attributes

float closeEnoughDistance = 0.1f
 How close should path following get before it considers itself "close enough" to stop moving.
float closeEnoughAngle = 5f
 How close does orientation/facing behavior need to get before it considers itself "close enough" to stop turning.
float faceBeforeMoveAngle = 90f
 How close do we have to be facing before we start moving. If we are at less than this angle, we will turn in place before moving.
bool avoidObstacles = true
 avoidObstacles causes obstacle avoidance to be turned on. This works in conjunction with an obstacle avoidance sensor, which must be attached to the AI in order for avoidance to function correctly
float avoidRadius = 0.5f
 avoidRadius defines the distance to avoid obstacles by
float avoidanceSmoothingTime = 0.3f
 The amount of time to use as "memory" when smoothing obstacle avoidance. Too large a number will create strange wandering. To small a number will lead to jitter.
float avoidanceChecksPerSecond = 30.0f
 Number of times per second collisions are checked for avoidance.
float avoidanceStrength = 2.0f
 Avoidance Strength represents how much weight can be given to perpendicular avoidance vs forward movement. Example: 2.0 represents 2 parts avoidance (max) , one part forward.
bool useNavigationGrid = false
 Should the AI attempt to use a navigation grid for determining walkable areas during pathfinding.
int maxPathFindStepsPerFrame = 100
 Number of pathfinding steps allowed per frame. Lower # means pathfinding could take longer, but will consume less processing per AI per frame.
string navgridFilename
 Filename of the Navigation Grid when generating a mesh for the entire scene.
bool useWaypointFile = false
 Should the AI attempt to use waypoint information from a file for movement around the scene.
string waypointFilename
 Filename of the Waypoint navigation file. The file is loaded at runtime to define the Waypoint graph.
bool useWaypointCollection = true
 Should the AI attempt to use an attached waypoint collection to move.
GameObject waypointCollection
 waypointCollection is the GameObject parent of a collection of Waypoints that are managed by this PathManager
MoveLookTarget moveTarget
 moveTarget is the object or position that we want to move to
MoveLookTarget lookTarget
 lookTarget is the object or position that we want to look at
bool allow3DLook = true
 Should the look behavior allow full axis freedom.
WaypointPathGraph waypointPathGraph = null
 waypointPathGraph is the path graph used for Waypoint based pathfinding. This is usually set up automatically during the InitializeMovement call.
NavGridMultiRegionGraph gridPathGraph = null
 gridPathGraph is the path graph used for Nav Grid pathfinding. This is usually set up automatically during the InitializeMovement call
float minWaypointGraphRadius = 10.0f
 Minimum radius for generating recast graphs around a waypoint. Note that graphs are generated based on axis-aligned coordinates and not spheres, so this becomes a minimum square radius.
float pathNodeYTolerance = 2.0f
 Pathgraph operations that determine the position of an object on the graph require a tolerance in the vertical (Y) axis to cull out high and low points, for example on overhands or under a bridge. pathNodeYTolerance defines how much higher or lower a graph node can be from the AI to be considered.
bool showGraphWireframe = false
 showGraphWireFrame is used in the Unity Editor to toggle the wireframe visualization of the navigation graph
string navmeshFilename
 Filename of the Navigation Mesh when generating a mesh for the entire level.
string[] recastTagsToIgnore
bool[] recastLayerWhitelist = null
 recastLayerWhitelist is an array[32] of layer flags indicating whether the layer should be included in recast processing. If a layer is marked false, any colliders belonging to that layer are immediately culled from the processing list
bool advancedMode = false
 advancedMode is an Editor toggle defining whether advanced Recast options are displayed
float cellSize = 0.50f
 cellSize defines the cell unit size for rasterization during recast processing
float stepUpHeight = 1.0f
 stepUpHeight defines the max vertical distance between neighboring spans in recast processing to allow the spans to remain as walkable neighbors
float characterHeight = 2.0f
 characterHeight defines the minimum gap distance between overlapping spans in recast processing to allow the bottom span to remain walkable
float characterWidth = 1.0f
 characterWidth defines a diameter around the character defining the space required for obstacle avoidance
float maxHeightAlwaysWalkable = 0f
 maxHeightAlwaysWalkable defines a baseline height, under which spans are automatically marked walkable. This is a fixed span height irrespective of neighbors. It is primarily used to cull spikes in uneven terrain. Most users will want to leave this value set to 0
float maxSpanHeight = 0f
 maxSpanHeight defines the maximum height of any span, above which the span is considered unwalkable. This is a case-specific culling step used to eliminate high areas, for instance on castle walls. Most users will want to leave this value set to 0
float levelFloor = -100.0f
 levelFloor defines the lowest vertical position that will be considered allowable for recast processing. This is used to eliminate extra processing in low areas, and to cull items like skyboxes. This should be set below the minimum walkable position in the scene.
float levelCeiling = 100.0f
 levelCeiling defines the highest vertical position that will be considered allowable for recast processing. This is used to eliminate extra processing in high areas, and to cull items like skyboxes. This should be set above the maximum walkable position in the scene.
float maxWalkSlopeAngle = 45f
 maxWalkSlopeAngle determines the maximum angle that an AI can walk. Recast processing uses this value to cull steep geometry.
bool useAllLevelGeometry = false
 useAllLevelGeometry causes recast processing to include level geometry in addition to colliders and terrain. This value will normally be false, but may be activated when extra detail processing is required.
bool useColliders = true
 useColliders causes recast processing to include colliders in addition to level geometry and terrain. This value will normally be true.
bool useTerrain = true
 useTerrain causes recast processing to include terrain colliders in addition to level geometry and object colliders. This value may be true or false depending on how ground is setup.

Detailed Description

PathManager is both a helper class for building pathfinding within the UnityEditor and a utility class for accessing path-based movement in RAIN.


Constructor & Destructor Documentation

RAIN.Path.PathManager.PathManager ( )

Default constructor.

RAIN.Path.PathManager.PathManager ( )

Default constructor.


Member Function Documentation

void RAIN.Path.PathManager.Avoid ( Agent  agent,
float  deltaTime 
)

Execute the avoid step - perform obstacle avoidance movement. Note that this is called by Move automatically if obstacle avoidance is enabled.

Parameters:
agentAI Agent
deltaTimeTime step
void RAIN.Path.PathManager.Awake ( )

Awake is the Unity event handler for component activation.

void RAIN.Path.PathManager.Awake ( )

Awake is the Unity event handler for component activation.

static void RAIN.Path.PathManager.ClearSharedGraphs ( ) [static]

Clear out all shared graphs so that the next request for a path graph will require a reload.

void RAIN.Path.PathManager.CreateMoveLookTargets ( )

Ensure that the moveTarget and lookTarget variables are not null. If they are null, create new objects, otherwise do nothing.

void RAIN.Path.PathManager.GenerateNavigationGraphForWaypoint ( string  filename,
Waypoint  wp 
)

GenerateNavigationGraphForWaypoint generates a local navigation mesh between the waypoint and its neighbors.

Parameters:
filenamethe name of the file to write results into
wpthe waypoint to generate a graph around
bool RAIN.Path.PathManager.GetPathToMoveTarget ( Agent  agent,
float  deltaTime,
out PathBase  path 
)

Attempt to create a path from the agent to the current moveTarget. This method may work across multiple calls, only performing part of the pathfind during each call.

Parameters:
agentThe AI Agent
deltaTimeTime step in seconds
pathAn out variable that will contain the path upon completion.
Returns:
True if pathfinding is finished, false if more work remains.
void RAIN.Path.PathManager.LoadNavigationGridGraphFromFile ( string  filename,
bool  replaceExistingGraph 
)

Load the gridPathGraph from a file. The graph will be stored in the shared graph array for sharing with other AI.

Parameters:
filenameThe grid graph filename to load, with no path or file extension
replaceExistingGraphif true, a new graph will be loaded. If the load fails, the current graph will not be replaced.
bool RAIN.Path.PathManager.LoadQuadFieldPathGraph ( )

Load the quad field path graph defined in the navmeshFilename.

Returns:
true if successful, false otherwise
void RAIN.Path.PathManager.LoadWaypointGraphFromCollection ( GameObject  collection,
bool  replaceExistingGraph 
)

Load the waypointPathGraph from the named waypoint collection. If a graph is already loaded and replaceExistingGraph is false, this will do nothing.

Parameters:
collectionA GameObject whose children are Waypoint objects
replaceExistingGraphif true, any existing graph will be overwritten
void RAIN.Path.PathManager.LoadWaypointGraphFromFile ( string  filename,
bool  replaceExistingGraph 
)

Set the waypointFilename to the specified filename, then load the graph. If a waypointgraph has already been loaded and replaceExistingGraph is false, this will do nothing The graph will be stored in the shared graph array for sharing with other AI.

Parameters:
filenameThe waypoint graph filename to load, with no path or file extension
replaceExistingGraphif true, a new graph will always be loaded.
bool RAIN.Path.PathManager.Look ( Agent  agent,
float  deltaTime 
)

Execute the look step - turn to face the looktarget.

Parameters:
agentAI Agent
deltaTimeTime step
Returns:
returns true if the result is that the AI is looking at the lookTarget, false if more time steps are required
bool RAIN.Path.PathManager.LookAt ( Agent  agent,
float  deltaTime,
Vector3  position 
)

Set the lookTarget to a particular position and then Look at it.

Parameters:
agentAI Agent
deltaTimeTime step
positionVector3 position to look at
Returns:
returns true if the result is that the AI is looking at the position, false if more time steps are required
bool RAIN.Path.PathManager.Move ( Agent  agent,
float  deltaTime 
)

Execute the move step - proceeding to the moveTarget based on the current path setup.

Parameters:
agentAI Agent
deltaTimeTime step
Returns:
true if the move target is reached, false if the agent is further than closeEnough distance from the move target
bool RAIN.Path.PathManager.MoveTo ( Agent  agent,
float  deltaTime,
Vector3  position 
)

MoveTo will set the moveTarget to be a Vector target to the specified position, then call Move.

Parameters:
agentThe AI Agent
deltaTimeTime step in seconds
positionThe Vector3 position to move toward
Returns:
true if the position is reached, false if the agent is further than closeEnough distance from the position
void RAIN.Path.PathManager.OnDrawGizmos ( )

If we are drawing gizmos, attempt to draw the graph wireframe for any loaded recast quad field.

void RAIN.Path.PathManager.ReInit ( Agent  agent)

ReInit reinitializes the path manager to include any changed public variables, added files, etc.

void RAIN.Path.PathManager.ReInit ( )

ReInit reinitializes the path manager to include any changed public variables, added files, etc.

static void RAIN.Path.PathManager.ReplaceGraph ( string  filename,
PathGraph  pg 
) [static]

Replace a shared graph with a new one.

Parameters:
filenameThe graph filename to replace, with no path or file extension
pgThe PathGraph to store
static PathGraph RAIN.Path.PathManager.RetrieveGraph ( string  filename) [static]

Retrieve a pathgraph based on a filename. Use this method to obtain a shared graph instead of loading a new one.

Parameters:
filenameThe graph filename to retrieve, with no path or file extension
Returns:
Returns the shared path graph if one has been stored, null otherwise
bool RAIN.Path.PathManager.SaveQuadFieldGraph ( )

SaveQuadFieldGraph saves a navigation graph associated with the entire level.

Returns:
true on success, false otherwise
bool RAIN.Path.PathManager.SaveWaypointGraph ( )

SaveWaypointGraph saves all waypoints and connections from the WaypointCollection into a waypoint file.

Returns:
true on success, false otherwise
bool RAIN.Path.PathManager.SaveWaypointGraph ( )

SaveWaypointGraph saves all waypoints and connections from the WaypointCollection into a waypoint file.

Returns:
true on success, false otherwise
static void RAIN.Path.PathManager.StoreGraph ( string  filename,
PathGraph  pg 
) [static]

Store a loaded pathgraph for sharing.

Parameters:
filenameThe graph filename to store, with no path or file extension
pgThe PathGraph to store

Member Data Documentation

advancedMode is an Editor toggle defining whether advanced Recast options are displayed

Should the look behavior allow full axis freedom.

Number of times per second collisions are checked for avoidance.

The amount of time to use as "memory" when smoothing obstacle avoidance. Too large a number will create strange wandering. To small a number will lead to jitter.

Avoidance Strength represents how much weight can be given to perpendicular avoidance vs forward movement. Example: 2.0 represents 2 parts avoidance (max) , one part forward.

avoidObstacles causes obstacle avoidance to be turned on. This works in conjunction with an obstacle avoidance sensor, which must be attached to the AI in order for avoidance to function correctly

avoidRadius defines the distance to avoid obstacles by

cellSize defines the cell unit size for rasterization during recast processing

characterHeight defines the minimum gap distance between overlapping spans in recast processing to allow the bottom span to remain walkable

characterWidth defines a diameter around the character defining the space required for obstacle avoidance

How close does orientation/facing behavior need to get before it considers itself "close enough" to stop turning.

How close should path following get before it considers itself "close enough" to stop moving.

How close do we have to be facing before we start moving. If we are at less than this angle, we will turn in place before moving.

gridPathGraph is the path graph used for Nav Grid pathfinding. This is usually set up automatically during the InitializeMovement call

levelCeiling defines the highest vertical position that will be considered allowable for recast processing. This is used to eliminate extra processing in high areas, and to cull items like skyboxes. This should be set above the maximum walkable position in the scene.

levelFloor defines the lowest vertical position that will be considered allowable for recast processing. This is used to eliminate extra processing in low areas, and to cull items like skyboxes. This should be set below the minimum walkable position in the scene.

lookTarget is the object or position that we want to look at

maxHeightAlwaysWalkable defines a baseline height, under which spans are automatically marked walkable. This is a fixed span height irrespective of neighbors. It is primarily used to cull spikes in uneven terrain. Most users will want to leave this value set to 0

Number of pathfinding steps allowed per frame. Lower # means pathfinding could take longer, but will consume less processing per AI per frame.

maxSpanHeight defines the maximum height of any span, above which the span is considered unwalkable. This is a case-specific culling step used to eliminate high areas, for instance on castle walls. Most users will want to leave this value set to 0

maxWalkSlopeAngle determines the maximum angle that an AI can walk. Recast processing uses this value to cull steep geometry.

Minimum radius for generating recast graphs around a waypoint. Note that graphs are generated based on axis-aligned coordinates and not spheres, so this becomes a minimum square radius.

moveTarget is the object or position that we want to move to

Filename of the Navigation Grid when generating a mesh for the entire scene.

Filename of the Navigation Mesh when generating a mesh for the entire level.

Pathgraph operations that determine the position of an object on the graph require a tolerance in the vertical (Y) axis to cull out high and low points, for example on overhands or under a bridge. pathNodeYTolerance defines how much higher or lower a graph node can be from the AI to be considered.

recastLayerWhitelist is an array[32] of layer flags indicating whether the layer should be included in recast processing. If a layer is marked false, any colliders belonging to that layer are immediately culled from the processing list

showGraphWireFrame is used in the Unity Editor to toggle the wireframe visualization of the navigation graph

stepUpHeight defines the max vertical distance between neighboring spans in recast processing to allow the spans to remain as walkable neighbors

useAllLevelGeometry causes recast processing to include level geometry in addition to colliders and terrain. This value will normally be false, but may be activated when extra detail processing is required.

useColliders causes recast processing to include colliders in addition to level geometry and terrain. This value will normally be true.

Should the AI attempt to use a navigation grid for determining walkable areas during pathfinding.

useTerrain causes recast processing to include terrain colliders in addition to level geometry and object colliders. This value may be true or false depending on how ground is setup.

Should the AI attempt to use an attached waypoint collection to move.

Should the AI attempt to use waypoint information from a file for movement around the scene.

waypointCollection is the GameObject parent of a collection of Waypoints that are managed by this PathManager

Filename of the Waypoint navigation file. The file is loaded at runtime to define the Waypoint graph.

waypointPathGraph is the path graph used for Waypoint based pathfinding. This is usually set up automatically during the InitializeMovement call.