Example #1
0
        NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            // Get the graph type from the metadata we deserialized earlier
            var graphType = meta.GetGraphType(zipIndex);

            // Graph was null when saving, ignore
            if (System.Type.Equals(graphType, null))
            {
                return(null);
            }

            // Create a new graph of the right type
            var graph = System.Activator.CreateInstance(graphType) as NavGraph;

            graph.graphIndex = (uint)(graphIndex);

            var jsonName = "graph" + zipIndex + jsonExt;
            var binName  = "graph" + zipIndex + binaryExt;

            if (ContainsEntry(jsonName))
            {
                // Read the graph settings
                TinyJsonDeserializer.Deserialize(GetString(GetEntry(jsonName)), graphType, graph);
            }
            else if (ContainsEntry(binName))
            {
                var reader = GetBinaryReader(GetEntry(binName));
                var ctx    = new GraphSerializationContext(reader, null, graph.graphIndex, meta);
                ((IGraphInternals)graph).DeserializeSettingsCompatibility(ctx);
            }
            else
            {
                throw new FileNotFoundException("Could not find data for graph " + zipIndex + " in zip. Entry 'graph" + zipIndex + jsonExt + "' does not exist");
            }

            if (graph.guid.ToString() != meta.guids[zipIndex])
            {
                throw new Exception("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" + graph.guid + " != " + meta.guids[zipIndex]);
            }

            return(graph);
        }
Example #2
0
 private GraphMeta DeserializeMeta(ZipEntry entry)
 {
     return(TinyJsonDeserializer.Deserialize(GetString(entry), typeof(GraphMeta)) as GraphMeta);
 }