A* Pathfinding Project  4.1.11
The A* Pathfinding Project for Unity 3D
AstarSerializer Class Reference

Handles low level serialization and deserialization of graph settings and data. More...

Detailed Description

Handles low level serialization and deserialization of graph settings and data.

Mostly for internal use. You can use the methods in the AstarData class for higher level serialization and deserialization.

See also
AstarData

Public Member Functions

 AstarSerializer (AstarData data)
 
 AstarSerializer (AstarData data, SerializeSettings settings)
 
void CloseDeserialize ()
 
byte [] CloseSerialize ()
 
void DeserializeEditorSettingsCompatibility ()
 Deserializes graph editor settings. More...
 
void DeserializeExtraInfo ()
 Deserializes extra graph info. More...
 
NavGraph [] DeserializeGraphs ()
 Deserializes graph settings. More...
 
uint GetChecksum ()
 
bool OpenDeserialize (byte[] bytes)
 
void OpenSerialize ()
 
void PostDeserialization ()
 Calls PostDeserialization on all loaded graphs. More...
 
byte [] Serialize (NavGraph graph)
 Serializes the graph settings to JSON and returns the data. More...
 
void SerializeExtraInfo ()
 
void SerializeGraphs (NavGraph[] _graphs)
 
void SerializeNodes ()
 Deprecated method to serialize node data. More...
 
void SetGraphIndexOffset (int offset)
 

Static Public Member Functions

static byte [] LoadFromFile (string path)
 Load the specified data from the specified path. More...
 
static void SaveToFile (string path, byte[] data)
 Save the specified data at the specified path. More...
 

Static Public Attributes

static readonly System.Version V3_8_3 = new System.Version(3, 8, 3)
 Cached version object for 3.8.3. More...
 
static readonly System.Version V3_9_0 = new System.Version(3, 9, 0)
 Cached version object for 3.9.0. More...
 
static readonly System.Version V4_1_0 = new System.Version(4, 1, 0)
 Cached version object for 4.1.0. More...
 

Private Member Functions

void AddChecksum (byte[] bytes)
 
void AddEntry (string name, byte[] bytes)
 
bool AnyDestroyedNodesInGraphs ()
 
bool ContainsEntry (string name)
 
GraphMeta DeserializeBinaryMeta (ZipEntry entry)
 
bool DeserializeExtraInfo (NavGraph graph)
 
NavGraph DeserializeGraph (int zipIndex, int graphIndex)
 
GraphMeta DeserializeMeta (ZipEntry entry)
 
void DeserializeNodeLinks (GraphNode[] int2Node)
 
GraphNode [] DeserializeNodeReferenceMap ()
 
void DeserializeNodeReferences (NavGraph graph, GraphNode[] int2Node)
 
ZipEntry GetEntry (string name)
 
byte [] SerializeMeta ()
 Serialize metadata about all graphs. More...
 
byte [] SerializeNodeLinks ()
 

Static Private Member Functions

static System.Version FullyDefinedVersion (System.Version v)
 Returns a version with all fields fully defined. More...
 
static BinaryReader GetBinaryReader (ZipEntry entry)
 Returns a binary reader for the data in the zip entry. More...
 
static int GetMaxNodeIndexInAllGraphs (NavGraph[] graphs)
 
static string GetString (ZipEntry entry)
 Returns the data in the zip entry as a string. More...
 
static System.Text.StringBuilder GetStringBuilder ()
 Returns a cached StringBuilder. More...
 
static byte [] SerializeGraphExtraInfo (NavGraph graph)
 Serializes info returned by NavGraph.SerializeExtraInfo. More...
 
static byte [] SerializeGraphNodeReferences (NavGraph graph)
 Used to serialize references to other nodes e.g connections. More...
 
static byte [] SerializeNodeIndices (NavGraph[] graphs)
 

Private Attributes

const string binaryExt = ".binary"
 Extension to use for binary files. More...
 
uint checksum = 0xffffffff
 Checksum for the serialized data. More...
 
AstarData data
 
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding()
 
Dictionary< NavGraph, int > graphIndexInZip
 Index used for the graph in the file. More...
 
int graphIndexOffset
 
NavGraph [] graphs
 Graphs that are being serialized or deserialized. More...
 
const string jsonExt = ".json"
 Extension to use for json files. More...
 
GraphMeta meta
 Graph metadata. More...
 
SerializeSettings settings
 Settings for serialization. More...
 
ZipFile zip
 Zip which the data is loaded from. More...
 
MemoryStream zipStream
 Memory stream with the zip data. More...
 

Static Private Attributes

static System.Text.StringBuilder _stringBuilder = new System.Text.StringBuilder()
 Cached StringBuilder to avoid excessive allocations. More...
 

Constructor & Destructor Documentation

◆ AstarSerializer() [1/2]

◆ AstarSerializer() [2/2]

AstarSerializer ( AstarData  data,
SerializeSettings  settings 
)

Member Function Documentation

◆ AddChecksum()

void AddChecksum ( byte []  bytes)
private

◆ AddEntry()

void AddEntry ( string  name,
byte []  bytes 
)
private

◆ AnyDestroyedNodesInGraphs()

bool AnyDestroyedNodesInGraphs ( )
private

◆ CloseDeserialize()

void CloseDeserialize ( )

◆ CloseSerialize()

byte [] CloseSerialize ( )

◆ ContainsEntry()

bool ContainsEntry ( string  name)
private

◆ DeserializeBinaryMeta()

GraphMeta DeserializeBinaryMeta ( ZipEntry  entry)
private

◆ DeserializeEditorSettingsCompatibility()

void DeserializeEditorSettingsCompatibility ( )

Deserializes graph editor settings.

For future compatibility this method does not assume that the graphEditors array matches the graphs array in order and/or count. It searches for a matching graph (matching if graphEditor.target == graph) for every graph editor. Multiple graph editors should not refer to the same graph.

Note
Stored in files named "graph#_editor.json" where # is the graph number.
This method is only used for compatibility, newer versions store everything in the graph.serializedEditorSettings field which is already serialized.

◆ DeserializeExtraInfo() [1/2]

bool DeserializeExtraInfo ( NavGraph  graph)
private

◆ DeserializeExtraInfo() [2/2]

void DeserializeExtraInfo ( )

Deserializes extra graph info.

Extra graph info is specified by the graph types.

See also
Pathfinding.NavGraph.DeserializeExtraInfo
Note
Stored in files named "graph#_extra.binary" where # is the graph number.

◆ DeserializeGraph()

NavGraph DeserializeGraph ( int  zipIndex,
int  graphIndex 
)
private

◆ DeserializeGraphs()

NavGraph [] DeserializeGraphs ( )

Deserializes graph settings.

Note
Stored in files named "graph#.json" where # is the graph number.

◆ DeserializeMeta()

GraphMeta DeserializeMeta ( ZipEntry  entry)
private

◆ DeserializeNodeLinks()

void DeserializeNodeLinks ( GraphNode []  int2Node)
private

◆ DeserializeNodeReferenceMap()

GraphNode [] DeserializeNodeReferenceMap ( )
private

◆ DeserializeNodeReferences()

void DeserializeNodeReferences ( NavGraph  graph,
GraphNode []  int2Node 
)
private

◆ FullyDefinedVersion()

static System.Version FullyDefinedVersion ( System.Version  v)
staticprivate

Returns a version with all fields fully defined.

This is used because by default new Version(3,0,0) > new Version(3,0). This is not the desired behaviour so we make sure that all fields are defined here

◆ GetBinaryReader()

static BinaryReader GetBinaryReader ( ZipEntry  entry)
staticprivate

Returns a binary reader for the data in the zip entry.

◆ GetChecksum()

uint GetChecksum ( )

◆ GetEntry()

ZipEntry GetEntry ( string  name)
private

◆ GetMaxNodeIndexInAllGraphs()

static int GetMaxNodeIndexInAllGraphs ( NavGraph []  graphs)
staticprivate

◆ GetString()

static string GetString ( ZipEntry  entry)
staticprivate

Returns the data in the zip entry as a string.

◆ GetStringBuilder()

static System.Text.StringBuilder GetStringBuilder ( )
staticprivate

Returns a cached StringBuilder.

This function only has one string builder cached and should thus only be called from a single thread and should not be called while using an earlier got string builder.

◆ LoadFromFile()

static byte [] LoadFromFile ( string  path)
static

Load the specified data from the specified path.

◆ OpenDeserialize()

bool OpenDeserialize ( byte []  bytes)

◆ OpenSerialize()

void OpenSerialize ( )

◆ PostDeserialization()

void PostDeserialization ( )

Calls PostDeserialization on all loaded graphs.

◆ SaveToFile()

static void SaveToFile ( string  path,
byte []  data 
)
static

Save the specified data at the specified path.

◆ Serialize()

byte [] Serialize ( NavGraph  graph)

Serializes the graph settings to JSON and returns the data.

◆ SerializeExtraInfo()

void SerializeExtraInfo ( )

◆ SerializeGraphExtraInfo()

static byte [] SerializeGraphExtraInfo ( NavGraph  graph)
staticprivate

Serializes info returned by NavGraph.SerializeExtraInfo.

◆ SerializeGraphNodeReferences()

static byte [] SerializeGraphNodeReferences ( NavGraph  graph)
staticprivate

Used to serialize references to other nodes e.g connections.

Nodes use the GraphSerializationContext.GetNodeIdentifier and GraphSerializationContext.GetNodeFromIdentifier methods for serialization and deserialization respectively.

◆ SerializeGraphs()

void SerializeGraphs ( NavGraph []  _graphs)

◆ SerializeMeta()

byte [] SerializeMeta ( )
private

Serialize metadata about all graphs.

◆ SerializeNodeIndices()

static byte [] SerializeNodeIndices ( NavGraph []  graphs)
staticprivate

◆ SerializeNodeLinks()

byte [] SerializeNodeLinks ( )
private

◆ SerializeNodes()

void SerializeNodes ( )

Deprecated method to serialize node data.

Deprecated:
Not used anymore

◆ SetGraphIndexOffset()

void SetGraphIndexOffset ( int  offset)

Member Data Documentation

◆ _stringBuilder

System.Text.StringBuilder _stringBuilder = new System.Text.StringBuilder()
staticprivate

Cached StringBuilder to avoid excessive allocations.

◆ binaryExt

const string binaryExt = ".binary"
private

Extension to use for binary files.

◆ checksum

uint checksum = 0xffffffff
private

Checksum for the serialized data.

Used to provide a quick equality check in editor code

◆ data

AstarData data
private

◆ encoding

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding()
private

◆ graphIndexInZip

Dictionary<NavGraph, int> graphIndexInZip
private

Index used for the graph in the file.

If some graphs were null in the file then graphIndexInZip[graphs[i]] may not equal i. Used for deserialization.

◆ graphIndexOffset

int graphIndexOffset
private

◆ graphs

NavGraph [] graphs
private

Graphs that are being serialized or deserialized.

◆ jsonExt

const string jsonExt = ".json"
private

Extension to use for json files.

◆ meta

GraphMeta meta
private

Graph metadata.

◆ settings

SerializeSettings settings
private

Settings for serialization.

◆ V3_8_3

readonly System.Version V3_8_3 = new System.Version(3, 8, 3)
static

Cached version object for 3.8.3.

◆ V3_9_0

readonly System.Version V3_9_0 = new System.Version(3, 9, 0)
static

Cached version object for 3.9.0.

◆ V4_1_0

readonly System.Version V4_1_0 = new System.Version(4, 1, 0)
static

Cached version object for 4.1.0.

◆ zip

ZipFile zip
private

Zip which the data is loaded from.

◆ zipStream

MemoryStream zipStream
private

Memory stream with the zip data.


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