Exemplo n.º 1
0
        /// <summary>Serialize metadata about all graphs</summary>
        byte[] SerializeMeta()
        {
            if (graphs == null)
            {
                throw new System.Exception("No call to SerializeGraphs has been done");
            }

            meta.version   = AstarPath.Version;
            meta.graphs    = graphs.Length;
            meta.guids     = new List <string>();
            meta.typeNames = new List <string>();

            // For each graph, save the guid
            // of the graph and the type of it
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    meta.guids.Add(graphs[i].guid.ToString());
                    meta.typeNames.Add(graphs[i].GetType().FullName);
                }
                else
                {
                    meta.guids.Add(null);
                    meta.typeNames.Add(null);
                }
            }

            // Grab a cached string builder to avoid allocations
            var output = GetStringBuilder();

            TinyJsonSerializer.Serialize(meta, output);
            return(encoding.GetBytes(output.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>Serializes the graph settings to JSON and returns the data</summary>
        public byte[] Serialize(NavGraph graph)
        {
            // Grab a cached string builder to avoid allocations
            var output = GetStringBuilder();

            TinyJsonSerializer.Serialize(graph, output);
            return(encoding.GetBytes(output.ToString()));
        }