本文整理汇总了C#中Pathfinding.Serialization.GraphSerializationContext类的典型用法代码示例。如果您正苦于以下问题:C# GraphSerializationContext类的具体用法?C# GraphSerializationContext怎么用?C# GraphSerializationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GraphSerializationContext类属于Pathfinding.Serialization命名空间,在下文中一共展示了GraphSerializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeExtraInfo
public override void DeserializeExtraInfo (GraphSerializationContext ctx) {
//NavMeshGraph.DeserializeMeshNodes (this,nodes,bytes);
System.IO.BinaryReader reader = ctx.reader;
tileXCount = reader.ReadInt32();
if (tileXCount < 0) return;
tileZCount = reader.ReadInt32();
tiles = new NavmeshTile[tileXCount * tileZCount];
//Make sure mesh nodes can reference this graph
TriangleMeshNode.SetNavmeshHolder (ctx.graphIndex, this);
for (int z=0;z<tileZCount;z++) {
for (int x=0;x<tileXCount;x++) {
int tileIndex = x + z*tileXCount;
int tx = reader.ReadInt32();
if (tx < 0) throw new System.Exception ("Invalid tile coordinates (x < 0)");
int tz = reader.ReadInt32();
if (tz < 0) throw new System.Exception ("Invalid tile coordinates (z < 0)");
// This is not the origin of a large tile. Refer back to that tile.
if (tx != x || tz != z) {
tiles[tileIndex] = tiles[tz*tileXCount + tx];
continue;
}
NavmeshTile tile = new NavmeshTile ();
tile.x = tx;
tile.z = tz;
tile.w = reader.ReadInt32();
tile.d = reader.ReadInt32();
tile.bbTree = new BBTree (tile);
tiles[tileIndex] = tile;
int trisCount = reader.ReadInt32 ();
if (trisCount % 3 != 0) throw new System.Exception ("Corrupt data. Triangle indices count must be divisable by 3. Got " + trisCount);
tile.tris = new int[trisCount];
for (int i=0;i<tile.tris.Length;i++) tile.tris[i] = reader.ReadInt32();
tile.verts = new Int3[reader.ReadInt32()];
for (int i=0;i<tile.verts.Length;i++) {
tile.verts[i] = new Int3 (reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
}
int nodeCount = reader.ReadInt32();
tile.nodes = new TriangleMeshNode[nodeCount];
//Prepare for storing in vertex indices
tileIndex <<= TileIndexOffset;
for (int i=0;i<tile.nodes.Length;i++) {
TriangleMeshNode node = new TriangleMeshNode (active);
tile.nodes[i] = node;
node.GraphIndex = (uint)ctx.graphIndex;
node.DeserializeNode (ctx);
node.v0 = tile.tris[i*3+0] | tileIndex;
node.v1 = tile.tris[i*3+1] | tileIndex;
node.v2 = tile.tris[i*3+2] | tileIndex;
node.UpdatePositionFromVertices();
tile.bbTree.Insert (node);
}
}
}
}
示例2: SerializeNode
public override void SerializeNode (GraphSerializationContext ctx)
{
base.SerializeNode (ctx);
ctx.writer.Write (position.x);
ctx.writer.Write (position.y);
ctx.writer.Write (position.z);
}
示例3: SerializeReferences
public override void SerializeReferences (GraphSerializationContext ctx)
{
if (connections == null) {
ctx.writer.Write(-1);
} else {
ctx.writer.Write (connections.Length);
for (int i=0;i<connections.Length;i++) {
ctx.writer.Write (ctx.GetNodeIdentifier (connections[i]));
ctx.writer.Write (connectionCosts[i]);
}
}
}
示例4: DeserializeNode
public override void DeserializeNode (GraphSerializationContext ctx)
{
base.DeserializeNode (ctx);
position = new Int3(ctx.reader.ReadInt32(), ctx.reader.ReadInt32(), ctx.reader.ReadInt32());
gridFlags = ctx.reader.ReadUInt16();
#if ASTAR_LEVELGRIDNODE_FEW_LAYERS
gridConnections = ctx.reader.ReadUInt16();
#else
gridConnections = ctx.reader.ReadUInt32();
#endif
}
示例5: SerializeExtraInfo
public override void SerializeExtraInfo (GraphSerializationContext ctx)
{
if (nodes == null) {
ctx.writer.Write(-1);
return;
}
ctx.writer.Write (nodes.Length);
for (int i=0;i<nodes.Length;i++) {
nodes[i].SerializeNode(ctx);
}
}
示例6: DeserializeSettings
public void DeserializeSettings ( GraphSerializationContext ctx ) {
type = (ColliderType)ctx.reader.ReadInt32();
diameter = ctx.reader.ReadSingle ();
height = ctx.reader.ReadSingle ();
collisionOffset = ctx.reader.ReadSingle ();
rayDirection = (RayDirection)ctx.reader.ReadInt32 ();
mask = (LayerMask)ctx.reader.ReadInt32 ();
heightMask = (LayerMask)ctx.reader.ReadInt32 ();
fromHeight = ctx.reader.ReadSingle ();
thickRaycast = ctx.reader.ReadBoolean ();
thickRaycastDiameter = ctx.reader.ReadSingle ();
unwalkableWhenNoGround = ctx.reader.ReadBoolean();
use2D = ctx.reader.ReadBoolean();
collisionCheck = ctx.reader.ReadBoolean();
heightCheck = ctx.reader.ReadBoolean();
}
示例7: SerializeNode
public virtual void SerializeNode(GraphSerializationContext ctx)
{
//Write basic node data.
ctx.writer.Write (Penalty);
ctx.writer.Write (Flags);
}
示例8: DeserializeGraphs
/** Deserializes graph settings.
* \note Stored in files named "graph#.json" where # is the graph number.
*/
public NavGraph[] DeserializeGraphs () {
// Allocate a list of graphs to be deserialized
graphs = new NavGraph[meta.graphs];
int nonNull = 0;
for (int i=0;i<meta.graphs;i++) {
// Get the graph type from the metadata we deserialized earlier
var tp = meta.GetGraphType(i);
// Graph was null when saving, ignore
if (System.Type.Equals (tp, null)) continue;
nonNull++;
var entry = zip["graph"+i+jsonExt];
if (entry == null)
throw new FileNotFoundException ("Could not find data for graph "+i+" in zip. Entry 'graph+"+i+jsonExt+"' does not exist");
// Create a new graph of the right type
NavGraph graph = data.CreateGraph(tp);
graph.graphIndex = (uint)(i + graphIndexOffset);
#if !ASTAR_NO_JSON
var entryText = GetString(entry);
var reader = new JsonReader(entryText,readerSettings);
reader.PopulateObject (ref graph);
#else
var mem = new MemoryStream ();
entry.Extract(mem);
mem.Position = 0;
var reader = new BinaryReader (mem);
var ctx = new GraphSerializationContext(reader, null, i + graphIndexOffset);
graph.DeserializeSettings (ctx);
#endif
graphs[i] = graph;
if (graphs[i].guid.ToString () != meta.guids[i])
throw new Exception ("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n"+graphs[i].guid+" != "+meta.guids[i]);
}
// Remove any null entries from the list
var compressed = new NavGraph[nonNull];
nonNull = 0;
for ( int i=0;i<graphs.Length;i++) {
if ( graphs[i] != null ) {
compressed[nonNull] = graphs[i];
nonNull++;
}
}
graphs = compressed;
return graphs;
}
示例9: DeserializeExtraInfo
/** Deserializes extra graph info.
* Extra graph info is specified by the graph types.
* \see Pathfinding.NavGraph.DeserializeExtraInfo
* \note Stored in files named "graph#_extra.binary" where # is the graph number.
*/
public void DeserializeExtraInfo () {
bool anySerialized = false;
// Loop through all graphs and deserialize the extra info
// if there is any such info in the zip file
for (int i=0;i<graphs.Length;i++) {
var entry = zip["graph"+i+"_extra"+binaryExt];
if (entry == null) continue;
anySerialized = true;
var str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
var reader = new BinaryReader (str);
var ctx = new GraphSerializationContext(reader, null, i + graphIndexOffset);
// Call the graph to process the data
graphs[i].DeserializeExtraInfo (ctx);
}
if (!anySerialized) {
return;
}
// Sanity check
// Make sure the graphs don't contain destroyed nodes
int totCount = 0;
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (delegate (GraphNode node) {
totCount = Math.Max (node.NodeIndex, totCount);
if (node.NodeIndex == -1) {
Debug.LogError ("Graph contains destroyed nodes. This is a bug.");
}
return true;
});
}
{
// Get the file containing the list of all node indices
// This is correlated with the new indices of the nodes and a mapping from old to new
// is done so that references can be resolved
var entry = zip["graph_references"+binaryExt];
if (entry == null) throw new Exception ("Node references not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
var str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
var reader = new BinaryReader (str);
int count = reader.ReadInt32();
var int2Node = new GraphNode[count+1];
try {
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (node => {
int2Node[reader.ReadInt32()] = node;
return true;
});
}
} catch (Exception e) {
throw new Exception ("Some graph(s) has thrown an exception during GetNodes, or some graph(s) have deserialized more or fewer nodes than were serialized", e);
}
#if NETFX_CORE
reader.Dispose();
#else
reader.Close ();
#endif
// Deserialize node references
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
entry = zip["graph"+i+"_references"+binaryExt];
if (entry == null) throw new Exception ("Node references for graph " +i + " not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
reader = new BinaryReader (str);
var ctx = new GraphSerializationContext(reader, int2Node, i + graphIndexOffset);
//.........这里部分代码省略.........
示例10: Serialize
/** Serializes the graph settings to JSON and returns the data */
public byte[] Serialize (NavGraph graph) {
#if !ASTAR_NO_JSON
// Grab a cached string builder to avoid allocations
var output = GetStringBuilder ();
var writer = new JsonWriter (output,writerSettings);
writer.Write (graph);
return encoding.GetBytes (output.ToString());
#else
var mem = new System.IO.MemoryStream();
var writer = new System.IO.BinaryWriter(mem);
var ctx = new GraphSerializationContext (writer);
graph.SerializeSettings (ctx);
return mem.ToArray();
#endif
}
示例11: SerializeExtraInfo
public void SerializeExtraInfo () {
if (!settings.nodes) return;
int totCount = 0;
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (node => {
totCount = Math.Max (node.NodeIndex, totCount);
if (node.NodeIndex == -1) {
Debug.LogError ("Graph contains destroyed nodes. This is a bug.");
}
return true;
});
}
{
var stream = new MemoryStream ();
var wr = new BinaryWriter (stream);
wr.Write (totCount);
int c = 0;
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (node => {
c = Math.Max (node.NodeIndex, c);
wr.Write (node.NodeIndex);
return true;
});
}
if (c != totCount) throw new Exception ("Some graphs are not consistent in their GetNodes calls, sequential calls give different results.");
byte[] bytes = stream.ToArray ();
#if NETFX_CORE
wr.Dispose();
#else
wr.Close ();
#endif
AddChecksum (bytes);
zip.AddEntry ("graph_references"+binaryExt,bytes);
}
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
var stream = new MemoryStream ();
var wr = new BinaryWriter (stream);
var ctx = new GraphSerializationContext(wr);
graphs[i].SerializeExtraInfo (ctx);
byte[] bytes = stream.ToArray ();
#if NETFX_CORE
wr.Dispose();
#else
wr.Close ();
#endif
AddChecksum (bytes);
zip.AddEntry ("graph"+i+"_extra"+binaryExt,bytes);
stream = new MemoryStream ();
wr = new BinaryWriter (stream);
ctx = new GraphSerializationContext(wr);
graphs[i].GetNodes (delegate (GraphNode node) {
node.SerializeReferences (ctx);
return true;
});
#if NETFX_CORE
wr.Dispose();
#else
wr.Close ();
#endif
bytes = stream.ToArray ();
AddChecksum (bytes);
zip.AddEntry ("graph"+i+"_references"+binaryExt,bytes);
}
}
示例12: DeserializeSettings
public override void DeserializeSettings (GraphSerializationContext ctx) {
base.DeserializeSettings(ctx);
aspectRatio = ctx.reader.ReadSingle();
rotation = ctx.DeserializeVector3();
center = ctx.DeserializeVector3();
unclampedSize = (Vector2)ctx.DeserializeVector3();
nodeSize = ctx.reader.ReadSingle();
collision.DeserializeSettings(ctx);
maxClimb = ctx.reader.ReadSingle();
maxClimbAxis = ctx.reader.ReadInt32();
maxSlope = ctx.reader.ReadSingle();
erodeIterations = ctx.reader.ReadInt32();
erosionUseTags = ctx.reader.ReadBoolean();
erosionFirstTag = ctx.reader.ReadInt32();
autoLinkGrids = ctx.reader.ReadBoolean();
neighbours = (NumNeighbours)ctx.reader.ReadInt32();
cutCorners = ctx.reader.ReadBoolean();
penaltyPosition = ctx.reader.ReadBoolean();
penaltyPositionFactor = ctx.reader.ReadSingle();
penaltyAngle = ctx.reader.ReadBoolean();
penaltyAngleFactor = ctx.reader.ReadSingle();
penaltyAnglePower = ctx.reader.ReadSingle();
isometricAngle = ctx.reader.ReadSingle();
uniformEdgeCosts = ctx.reader.ReadBoolean();
}
示例13: SerializeSettings
public override void SerializeSettings (GraphSerializationContext ctx) {
base.SerializeSettings(ctx);
ctx.writer.Write(aspectRatio);
ctx.SerializeVector3(rotation);
ctx.SerializeVector3(center);
ctx.SerializeVector3((Vector3)unclampedSize);
ctx.writer.Write(nodeSize);
// collision
collision.SerializeSettings(ctx);
ctx.writer.Write(maxClimb);
ctx.writer.Write(maxClimbAxis);
ctx.writer.Write(maxSlope);
ctx.writer.Write(erodeIterations);
ctx.writer.Write(erosionUseTags);
ctx.writer.Write(erosionFirstTag);
ctx.writer.Write(autoLinkGrids);
ctx.writer.Write((int)neighbours);
ctx.writer.Write(cutCorners);
ctx.writer.Write(penaltyPosition);
ctx.writer.Write(penaltyPositionFactor);
ctx.writer.Write(penaltyAngle);
ctx.writer.Write(penaltyAngleFactor);
ctx.writer.Write(penaltyAnglePower);
ctx.writer.Write(isometricAngle);
ctx.writer.Write(uniformEdgeCosts);
}
示例14: DeserializeExtraInfo
/** Deserializes extra graph info.
* Extra graph info is specified by the graph types.
* \see Pathfinding.NavGraph.DeserializeExtraInfo
* \note Stored in files named "graph#_extra.binary" where # is the graph number.
*/
public void DeserializeExtraInfo () {
bool anySerialized = false;
for (int i=0;i<graphs.Length;i++) {
ZipEntry entry = zip["graph"+i+"_extra"+binaryExt];
if (entry == null) continue;
anySerialized = true;
MemoryStream str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader (str);
//byte[] bytes = str.ToArray();
GraphSerializationContext ctx = new GraphSerializationContext(reader, null, i);
graphs[i].DeserializeExtraInfo (ctx);
}
if (!anySerialized) {
return;
}
int totCount = 0;
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (delegate (GraphNode node) {
totCount = System.Math.Max (node.NodeIndex, totCount);
if (node.NodeIndex == -1) {
Debug.LogError ("Graph contains destroyed nodes. This is a bug.");
}
return true;
});
}
{
// Get the file containing the list of all node indices
// This is correlated with the new indices of the nodes and a mapping from old to new
// is done so that references can be resolved
ZipEntry entry = zip["graph_references"+binaryExt];
if (entry == null) throw new System.Exception ("Node references not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
MemoryStream str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader (str);
int count = reader.ReadInt32();
GraphNode[] int2Node = new GraphNode[count+1];
try {
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
graphs[i].GetNodes (delegate (GraphNode node) {
int2Node[reader.ReadInt32()] = node;
return true;
});
}
} catch (System.Exception e) {
throw new System.Exception ("Some graph(s) has thrown an exception during GetNodes, or some graph(s) have deserialized more or fewer nodes than were serialized", e);
}
reader.Close();
// Deserialize node references
for (int i=0;i<graphs.Length;i++) {
if (graphs[i] == null) continue;
entry = zip["graph"+i+"_references"+binaryExt];
if (entry == null) throw new System.Exception ("Node references for graph " +i + " not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
str = new MemoryStream();
entry.Extract (str);
str.Seek (0, SeekOrigin.Begin);
reader = new BinaryReader (str);
GraphSerializationContext ctx = new GraphSerializationContext(reader, int2Node, i);
graphs[i].GetNodes (delegate (GraphNode node) {
node.DeserializeReferences (ctx);
return true;
});
}
}
}
示例15: DeserializeReferences
public override void DeserializeReferences(GraphSerializationContext ctx)
{
int num = ctx.reader.ReadInt32();
if (num == -1)
{
this.connections = null;
this.connectionCosts = null;
}
else
{
this.connections = new GraphNode[num];
this.connectionCosts = new uint[num];
for (int i = 0; i < num; i++)
{
this.connections[i] = ctx.GetNodeFromIdentifier(ctx.reader.ReadInt32());
this.connectionCosts[i] = ctx.reader.ReadUInt32();
}
}
}