예제 #1
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            Type graphType = this.meta.GetGraphType(zipIndex);

            if (object.Equals(graphType, null))
            {
                return(null);
            }
            NavGraph navGraph = this.data.CreateGraph(graphType);

            navGraph.graphIndex = (uint)graphIndex;
            string name  = "graph" + zipIndex + ".json";
            string name2 = "graph" + zipIndex + ".binary";

            if (this.ContainsEntry(name))
            {
                TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(this.GetEntry(name)), graphType, navGraph);
            }
            else
            {
                if (!this.ContainsEntry(name2))
                {
                    throw new FileNotFoundException(string.Concat(new object[]
                    {
                        "Could not find data for graph ",
                        zipIndex,
                        " in zip. Entry 'graph",
                        zipIndex,
                        ".json' does not exist"
                    }));
                }
                BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(this.GetEntry(name2));
                GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, null, navGraph.graphIndex, this.meta);
                navGraph.DeserializeSettingsCompatibility(ctx);
            }
            if (navGraph.guid.ToString() != this.meta.guids[zipIndex])
            {
                throw new Exception(string.Concat(new object[]
                {
                    "Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n",
                    navGraph.guid,
                    " != ",
                    this.meta.guids[zipIndex]
                }));
            }
            return(navGraph);
        }
예제 #2
0
        NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            // Get the graph type from the metadata we deserialized earlier
            var tp = meta.GetGraphType(zipIndex);

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

            // Create a new graph of the right type
            NavGraph graph = data.CreateGraph(tp);

            graph.graphIndex = (uint)(graphIndex);

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

            if (zip.ContainsEntry(jsonName))
            {
                // Read the graph settings
                TinyJsonDeserializer.Deserialize(GetString(zip[jsonName]), tp, graph);
            }
            else if (zip.ContainsEntry(binName))
            {
                var reader = GetBinaryReader(zip[binName]);
                var ctx    = new GraphSerializationContext(reader, null, graph.graphIndex, meta);
                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);
        }