A* Pathfinding Project  4.0.3
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
DynamicGridObstacle Class Reference

Attach this script to any obstacle with a collider to enable dynamic updates of the graphs around it. More...

Detailed Description

Attach this script to any obstacle with a collider to enable dynamic updates of the graphs around it.

When the object has moved a certain distance (or actually when it's bounding box has changed by a certain amount) defined by updateError it will call AstarPath.UpdateGraphs and update the graph around it.

Make sure that any children colliders do not extend beyond the bounds of the collider attached to the GameObject that the DynamicGridObstacle component is attached to since this script only updates the graph using the bounds of the collider on the same GameObject.

Note
This script only works with GridGraph, PointGraph and LayerGridGraph
See Also
AstarPath.UpdateGraphs
graph-updates

Public Member Functions

void DoUpdateGraphs ()
 Update the graphs around this object.
 
override void OnPostScan ()
 Called right after all graphs have been scanned.
 
- Public Member Functions inherited from GraphModifier
virtual void OnGraphsPostUpdate ()
 Called after graphs have been updated using GraphUpdateObjects.
 
virtual void OnGraphsPreUpdate ()
 Called before graphs are updated using GraphUpdateObjects.
 
virtual void OnLatePostScan ()
 Called at the end of the scanning procedure.
 
virtual void OnPostCacheLoad ()
 Called after cached graphs have been loaded.
 
virtual void OnPreScan ()
 Called right before graphs are going to be scanned.
 

Public Attributes

float checkTime = 0.2F
 Time in seconds between bounding box checks.
 
float updateError = 1
 The minimum change in world units along one of the axis of the bounding box of the collider to trigger a graph update.
 

Protected Member Functions

override void Awake ()
 
override void OnDestroy ()
 Revert graphs when destroyed.
 
- Protected Member Functions inherited from GraphModifier
virtual void OnDisable ()
 Removes this modifier from list of active modifiers.
 
virtual void OnEnable ()
 Adds this modifier to list of active modifiers.
 
- Protected Member Functions inherited from VersionedMonoBehaviour
virtual int OnUpgradeSerializedData (int version)
 Handle serialization backwards compatibility.
 

Private Member Functions

void Update ()
 

Static Private Member Functions

static float BoundsVolume (Bounds b)
 Volume of a Bounds object.
 

Private Attributes

Collider coll
 Collider to get bounds information from.
 
float lastCheckTime = -9999
 
Bounds prevBounds
 Bounds of the collider the last time the graphs were updated.
 
bool prevEnabled
 True if the collider was enabled last time the graphs were updated.
 
Quaternion prevRotation
 Rotation of the collider the last time the graphs were updated.
 
Transform tr
 Cached transform component.
 

Additional Inherited Members

- Public Types inherited from GraphModifier
enum  EventType {
  PostScan = 1 << 0, PreScan = 1 << 1, LatePostScan = 1 << 2, PreUpdate = 1 << 3,
  PostUpdate = 1 << 4, PostCacheLoad = 1 << 5
}
 GraphModifier event type. More...
 
- Static Public Member Functions inherited from GraphModifier
static void FindAllModifiers ()
 
static void TriggerEvent (GraphModifier.EventType type)
 Triggers an event for all active graph modifiers.
 
- Static Protected Member Functions inherited from GraphModifier
static List< T > GetModifiersOfType< T > ()
 
- Protected Attributes inherited from GraphModifier
ulong uniqueID
 Unique persistent ID for this component, used for serialization.
 
- Static Protected Attributes inherited from GraphModifier
static Dictionary< ulong,
GraphModifier
usedIDs = new Dictionary<ulong, GraphModifier>()
 Maps persistent IDs to the component that uses it.
 

Member Function Documentation

override void Awake ( )
protectedvirtual

Reimplemented from GraphModifier.

static float BoundsVolume ( Bounds  b)
staticprivate

Volume of a Bounds object.

X*Y*Z

void DoUpdateGraphs ( )

Update the graphs around this object.

Note
The graphs will not be updated immediately since the pathfinding threads need to be paused first. If you want to guarantee that the graphs have been updated then call AstarPath.active.FlushGraphUpdates() after the call to this method.
override void OnDestroy ( )
protectedvirtual

Revert graphs when destroyed.

When the DynamicObstacle is destroyed, a last graph update should be done to revert nodes to their original state

Reimplemented from GraphModifier.

override void OnPostScan ( )
virtual

Called right after all graphs have been scanned.

FloodFill and other post processing has not been done.

Warning
Since OnEnable and Awake are called roughly in the same time, the only way to ensure that these scripts get this call when scanning in Awake is to set the Script Execution Order for AstarPath to some time later than default time (see Edit -> Project Settings -> Script Execution Order).
Todo:
Is this still relevant? A call to FindAllModifiers should have before this method is called so the above warning is probably not relevant anymore.
See Also
OnLatePostScan

Reimplemented from GraphModifier.

void Update ( )
private

Member Data Documentation

float checkTime = 0.2F

Time in seconds between bounding box checks.

If AstarPath.batchGraphUpdates is enabled, it is not beneficial to have a checkTime much lower than AstarPath.graphUpdateBatchingInterval because that will just add extra unnecessary graph updates.

In real time seconds (based on Time.realtimeSinceStartup).

Collider coll
private

Collider to get bounds information from.

float lastCheckTime = -9999
private
Bounds prevBounds
private

Bounds of the collider the last time the graphs were updated.

bool prevEnabled
private

True if the collider was enabled last time the graphs were updated.

Quaternion prevRotation
private

Rotation of the collider the last time the graphs were updated.

Transform tr
private

Cached transform component.

float updateError = 1

The minimum change in world units along one of the axis of the bounding box of the collider to trigger a graph update.


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