示例#1
0
        private static byte[] SerializeNodeIndices(NavGraph[] graphs)
        {
            MemoryStream memoryStream            = new MemoryStream();
            BinaryWriter wr                      = new BinaryWriter(memoryStream);
            int          maxNodeIndexInAllGraphs = AstarSerializer.GetMaxNodeIndexInAllGraphs(graphs);

            wr.Write(maxNodeIndexInAllGraphs);
            int maxNodeIndex2 = 0;

            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    graphs[i].GetNodes(delegate(GraphNode node)
                    {
                        maxNodeIndex2 = Math.Max(node.NodeIndex, maxNodeIndex2);
                        wr.Write(node.NodeIndex);
                        return(true);
                    });
                }
            }
            if (maxNodeIndex2 != maxNodeIndexInAllGraphs)
            {
                throw new Exception("Some graphs are not consistent in their GetNodes calls, sequential calls give different results.");
            }
            byte[] result = memoryStream.ToArray();
            AstarSerializer.CloseOrDispose(wr);
            return(result);
        }
示例#2
0
        private static byte[] SerializeGraphExtraInfo(NavGraph graph)
        {
            MemoryStream memoryStream     = new MemoryStream();
            BinaryWriter writer           = new BinaryWriter(memoryStream);
            GraphSerializationContext ctx = new GraphSerializationContext(writer);

            graph.SerializeExtraInfo(ctx);
            byte[] result = memoryStream.ToArray();
            AstarSerializer.CloseOrDispose(writer);
            return(result);
        }
示例#3
0
        private static byte[] SerializeGraphNodeReferences(NavGraph graph)
        {
            MemoryStream memoryStream     = new MemoryStream();
            BinaryWriter writer           = new BinaryWriter(memoryStream);
            GraphSerializationContext ctx = new GraphSerializationContext(writer);

            graph.GetNodes(delegate(GraphNode node)
            {
                node.SerializeReferences(ctx);
                return(true);
            });
            AstarSerializer.CloseOrDispose(writer);
            return(memoryStream.ToArray());
        }