A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
AstarData Class Reference

Stores the navigation graphs for the A* Pathfinding System. More...

+ Collaboration diagram for AstarData:

Public Member Functions

NavGraph AddGraph (string type)
 Adds a graph of type type to the graphs array.
 
NavGraph AddGraph (System.Type type)
 Adds a graph of type type to the graphs array.
 
void AddGraph (NavGraph graph)
 Adds the specified graph to the graphs array.
 
void AssignNodeIndices ()
 
void Awake ()
 Loads the graphs from memory, will load cached graphs if any exists.
 
void CollectNodes (int numTemporary)
 
NavGraph CreateGraph (string type)
 Creates a new instance of a graph of type type.
 
NavGraph CreateGraph (System.Type type)
 Creates a new graph instance of type type.
 
void CreateNodeRuns (int numParallel)
 Creates the structure for holding temporary path data.
 
void DeserializeGraphs ()
 Deserializes graphs from data.
 
void DeserializeGraphs (byte[] bytes)
 Deserializes graphs from the specified byte array.
 
void DeserializeGraphs (AstarSerializer serializer)
 Main deserializer function (old), loads from the data variable.
 
void DeserializeGraphs (AstarSerializer serializer, byte[] bytes)
 Main deserializer function (old).
 
void DeserializeGraphs_oldInternal (AstarSerializer serializer)
 Main deserializer function (old), loads from the data variable.
 
void DeserializeGraphs_oldInternal (AstarSerializer serializer, byte[] bytes)
 Main deserializer function (old).
 
void DeserializeGraphsAdditive (byte[] bytes)
 Deserializes graphs from the specified byte array additively.
 
void DeserializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr)
 Deserializes common info.
 
void DeserializeGraphsPart (AstarSerializer serializer)
 Deserializes all graphs and also user connections.
 
void DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr)
 Deserializes common info additively Common info is what is shared between the editor serialization and the runtime serializer.
 
NavGraph FindGraphOfType (System.Type type)
 Returns the first graph of type type found in the graphs array.
 
IEnumerable FindGraphsOfType (System.Type type)
 Loop through this function to get all graphs of type 'type'.
 
void FindGraphTypes ()
 Find all graph types supported in this build.
 
byte[] GetData ()
 
int GetGraphIndex (NavGraph graph)
 Gets the index of the NavGraph in the graphs array.
 
System.Type GetGraphType (string type)
 
Node GetNode (int graphIndex, int nodeIndex)
 Returns the node at graphs[graphIndex].nodes[nodeIndex].
 
Node GetNode (int graphIndex, int nodeIndex, NavGraph[] graphs)
 Returns the node at graphs[graphIndex].nodes[nodeIndex].
 
IEnumerable GetRaycastableGraphs ()
 All graphs which implements the UpdateableGraph interface.
 
IEnumerable GetUpdateableGraphs ()
 All graphs which implements the UpdateableGraph interface.
 
NavGraph GuidToGraph (Guid guid)
 Tries to find a graph with the specified GUID in the graphs array.
 
int GuidToIndex (Guid guid)
 Tries to find a graph with the specified GUID in the graphs array.
 
void LoadFromCache ()
 
void RemoveGraph (NavGraph graph)
 Removes the specified graph from the graphs array and Destroys it in a safe manner.
 
void SaveCacheData (Pathfinding.Serialization.SerializeSettings settings)
 
byte[] SerializeGraphs ()
 Serializes all graphs settings to a byte array.
 
byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings)
 Main serializer function.
 
byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
 Main serializer function.
 
void SerializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr)
 Serializes common info to the serializer.
 
void SetData (byte[] data, uint checksum)
 
void UpdateShortcuts ()
 Updates shortcuts to the first graph of different types.
 

Static Public Member Functions

static NavGraph GetGraph (Node node)
 Returns the graph which contains the specified node.
 

Public Attributes

bool cacheStartup = false
 Should graph-data be cached.
 
bool compress = false
 
byte[] data_backup
 Backup data if deserialization failed.
 
byte[] data_cachedStartup
 Serialized data for cached startup.
 
uint dataChecksum
 
NavGraph[] graphs = new NavGraph[0]
 All graphs this instance holds.
 
System.Type[] graphTypes = null
 All supported graph types.
 
GridGraph gridGraph
 Shortcut to the first GridGraph.
 
bool hasBeenReverted = false
 Has the data been reverted by an undo operation.
 
NavMeshGraph navmesh
 Shortcut to the first NavMeshGraph.
 
NodeRun[][] nodeRuns
 Holds temporary path data for pathfinders.
 
PointGraph pointGraph
 Shortcut to the first PointGraph.
 
byte[] revertData
 
UserConnection[] userConnections = new UserConnection[0]
 Links placed by the user in the scene view.
 

Properties

AstarPath active [get]
 Shortcut to AstarPath.active.
 

Private Attributes

byte[] data
 Serialized data for all graphs and settings.
 

Detailed Description

Stores the navigation graphs for the A* Pathfinding System.

An instance of this class is assigned to AstarPath::astarData, from it you can access all graphs loaded through the graphs variable.
This class also handles a lot of the high level serialization.

Member Function Documentation

NavGraph CreateGraph ( string  type)

Creates a new instance of a graph of type type.

If no matching graph type was found, an error is logged and null is returned

Returns
The created graph
See Also
CreateGraph(System.Type)

+ Here is the caller graph for this function:

NavGraph CreateGraph ( System.Type  type)

Creates a new graph instance of type type.

See Also
CreateGraph(string)
void CreateNodeRuns ( int  numParallel)

Creates the structure for holding temporary path data.

The data is for example the G, H and F scores and the search tree. The number of nodeRuns must be no less than the number of nodes contained in all graphs. So after adding nodes, this MUST be called.
Ideally, I would code an update function which reuses most of the previous ones instead of recreating it every time.

Parameters
numParallelNumber of parallel threads which will use the data.
See Also
nodeRuns
AstarPath::UpdatePathThreadInfoNodes

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DeserializeGraphs ( byte[]  bytes)

Deserializes graphs from the specified byte array.

If an error ocurred, it will try to deserialize using the old deserializer. A warning will be logged if all deserializers failed.

+ Here is the call graph for this function:

void DeserializeGraphs ( AstarSerializer  serializer)

Main deserializer function (old), loads from the data variable.

Deprecated:

+ Here is the call graph for this function:

void DeserializeGraphs ( AstarSerializer  serializer,
byte[]  bytes 
)

Main deserializer function (old).

Loads from bytes variable

Deprecated:

+ Here is the call graph for this function:

void DeserializeGraphs_oldInternal ( AstarSerializer  serializer)

Main deserializer function (old), loads from the data variable.

Deprecated:

+ Here is the caller graph for this function:

void DeserializeGraphs_oldInternal ( AstarSerializer  serializer,
byte[]  bytes 
)

Main deserializer function (old).

Loads from bytes variable

Deprecated:

+ Here is the call graph for this function:

void DeserializeGraphsAdditive ( byte[]  bytes)

Deserializes graphs from the specified byte array additively.

If an error ocurred, it will try to deserialize using the old deserializer. A warning will be logged if all deserializers failed. This function will add loaded graphs to the current ones

+ Here is the call graph for this function:

void DeserializeGraphsPart ( Pathfinding.Serialization.AstarSerializer  sr)

Deserializes common info.

Common info is what is shared between the editor serialization and the runtime serializer. This is mostly everything except the graph inspectors which serialize some extra data in the editor

+ Here is the caller graph for this function:

void DeserializeGraphsPart ( AstarSerializer  serializer)

Deserializes all graphs and also user connections.

Deprecated:

+ Here is the call graph for this function:

void DeserializeGraphsPartAdditive ( Pathfinding.Serialization.AstarSerializer  sr)

Deserializes common info additively Common info is what is shared between the editor serialization and the runtime serializer.

This is mostly everything except the graph inspectors which serialize some extra data in the editor

+ Here is the caller graph for this function:

NavGraph FindGraphOfType ( System.Type  type)

Returns the first graph of type type found in the graphs array.

Returns null if none was found

+ Here is the caller graph for this function:

IEnumerable FindGraphsOfType ( System.Type  type)

Loop through this function to get all graphs of type 'type'.

foreach (GridGraph graph in AstarPath.astarData.FindGraphsOfType (typeof(GridGraph))) {
//Do something with the graph
}
See Also
AstarPath::RegisterSafeNodeUpdate
void FindGraphTypes ( )

Find all graph types supported in this build.

Using reflection, the assembly is searched for types which inherit from NavGraph.

+ Here is the caller graph for this function:

static NavGraph GetGraph ( Node  node)
static

Returns the graph which contains the specified node.

The graph must be in the graphs array.

Returns
Returns the graph which contains the node. Null if the graph wasn't found

+ Here is the caller graph for this function:

System.Type GetGraphType ( string  type)
Returns
A System.Type which matches the specified type string. If no mathing graph type was found, null is returned
Node GetNode ( int  graphIndex,
int  nodeIndex 
)

Returns the node at graphs[graphIndex].nodes[nodeIndex].

All kinds of error checking is done to make sure no exceptions are thrown.

Node GetNode ( int  graphIndex,
int  nodeIndex,
NavGraph[]  graphs 
)

Returns the node at graphs[graphIndex].nodes[nodeIndex].

The graphIndex refers to the specified graphs array.
All kinds of error checking is done to make sure no exceptions are thrown

IEnumerable GetRaycastableGraphs ( )

All graphs which implements the UpdateableGraph interface.

foreach (IRaycastableGraph graph in AstarPath.astarData.GetRaycastableGraphs ()) {
//Do something with the graph
}
See Also
Pathfinding::IRaycastableGraph
IEnumerable GetUpdateableGraphs ( )

All graphs which implements the UpdateableGraph interface.

foreach (IUpdatableGraph graph in AstarPath.astarData.GetUpdateableGraphs ()) {
//Do something with the graph
}
See Also
AstarPath::RegisterSafeNodeUpdate
Pathfinding::IUpdatableGraph

+ Here is the caller graph for this function:

NavGraph GuidToGraph ( Guid  guid)

Tries to find a graph with the specified GUID in the graphs array.

Returns null if none is found

See Also
GuidToIndex

+ Here is the caller graph for this function:

int GuidToIndex ( Guid  guid)

Tries to find a graph with the specified GUID in the graphs array.

If a graph is found it returns its index, otherwise it returns -1

See Also
GuidToGraph
byte [] SerializeGraphs ( )

Serializes all graphs settings to a byte array.

See Also
DeserializeGraphs(byte[])

+ Here is the caller graph for this function:

byte [] SerializeGraphs ( Pathfinding.Serialization.SerializeSettings  settings)

Main serializer function.

+ Here is the call graph for this function:

byte [] SerializeGraphs ( Pathfinding.Serialization.SerializeSettings  settings,
out uint  checksum 
)

Main serializer function.

Serializes all graphs to a byte array A similar function exists in the AstarEditor.cs script to save additional info

+ Here is the call graph for this function:

void SerializeGraphsPart ( Pathfinding.Serialization.AstarSerializer  sr)

Serializes common info to the serializer.

Common info is what is shared between the editor serialization and the runtime serializer. This is mostly everything except the graph inspectors which serialize some extra data in the editor

+ Here is the caller graph for this function:

void UpdateShortcuts ( )

Updates shortcuts to the first graph of different types.

Hard coding references to some graph types is not really a good thing imo. I want to keep it dynamic and flexible. But these references ease the use of the system, so I decided to keep them. It is the only reference to specific graph types in the pathfinding core.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool cacheStartup = false

Should graph-data be cached.

Caching the startup means saving the whole graphs, not only the settings to an internal array (data_cachedStartup) which can be loaded faster than scanning all graphs at startup. This is setup from the editor.

NavGraph [] graphs = new NavGraph[0]

All graphs this instance holds.

This will be filled only after deserialization has completed

System.Type [] graphTypes = null

All supported graph types.

Populated through reflection search

GridGraph gridGraph

Shortcut to the first GridGraph.

Updated at scanning time. This is the only reference to GridGraph in the core pathfinding scripts

bool hasBeenReverted = false

Has the data been reverted by an undo operation.

Used by the editor's undo logic to check if the AstarData has been reverted by an undo operation and should be deserialized

NavMeshGraph navmesh

Shortcut to the first NavMeshGraph.

Updated at scanning time. This is the only reference to NavMeshGraph in the core pathfinding scripts

NodeRun [][] nodeRuns

Holds temporary path data for pathfinders.

One array for every thread. Every array is itself an array with a number of NodeRun object of which there is one per node of. These objects holds the temporary path data, such as the G and H scores and the parent node. This is separate from the static path data, e.g connections between nodes.

See Also
CreateNodeRuns
PointGraph pointGraph

Shortcut to the first PointGraph.

Updated at scanning time. This is the only reference to PointGraph in the core pathfinding scripts

UserConnection [] userConnections = new UserConnection[0]

Links placed by the user in the scene view.


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