GetGraphType() public method

public GetGraphType ( int i ) : Type
i int
return System.Type
        /** Deserializes graph settings.
         * \note Stored in files named "graph#.json" where # is the graph number.
         */
        public NavGraph[] DeserializeGraphs()
        {
            //for (int j=0;j<1;j++) {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();

            graphs = new NavGraph[meta.graphs];

            for (int i = 0; i < meta.graphs; i++)
            {
                Type tp = meta.GetGraphType(i);

                //Graph was null when saving, ignore
                if (tp == null)
                {
                    continue;
                }

                ZipEntry 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");
                }

                //Debug.Log ("Reading graph " +i+" with type "+tp.FullName);
                String entryText = GetString(entry);
                //Debug.Log (entryText);

                NavGraph   tmp    = data.CreateGraph(tp);           //(NavGraph)System.Activator.CreateInstance(tp);
                JsonReader reader = new JsonReader(entryText, readerSettings);

                //NavGraph graph = tmp.Deserialize(reader);//reader.Deserialize<NavGraph>();
                reader.PopulateObject(tmp);

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

                //NavGraph graph = (NavGraph)JsonConvert.DeserializeObject (entryText,tp,settings);
            }

            return(graphs);

            //watch.Stop();
            //Debug.Log ((watch.ElapsedTicks*0.0001).ToString ("0.00"));
            //}
        }
Exemplo n.º 2
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex, Type[] availableGraphTypes)
        {
            // Get the graph type from the metadata we deserialized earlier
            var graphType = meta.GetGraphType(zipIndex, availableGraphTypes);

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

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

            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);
        }
Exemplo n.º 3
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);
            }

            var entry = zip["graph" + zipIndex + jsonExt];

            if (entry == null)
            {
                throw new FileNotFoundException("Could not find data for graph " + zipIndex + " in zip. Entry 'graph" + zipIndex + jsonExt + "' does not exist");
            }

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

            graph.graphIndex = (uint)(graphIndex);

#if !ASTAR_NO_JSON
            var entryText = GetString(entry);
            var reader    = new JsonReader(entryText, readerSettings);

            // Read the graph settings
            reader.PopulateObject(ref graph);
#else
            var reader = GetBinaryReader(entry);
            var ctx    = new GraphSerializationContext(reader, null, graph.graphIndex);
            graph.DeserializeSettings(ctx);
#endif

            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);
        }
Exemplo n.º 4
0
        /** Deserializes graph settings.
         * \note Stored in files named "graph#.json" where # is the graph number.
         */
        public NavGraph[] DeserializeGraphs()
        {
            //for (int j=0;j<1;j++) {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();

            graphs = new NavGraph[meta.graphs];

            int nonNull = 0;

            for (int i = 0; i < meta.graphs; i++)
            {
                Type tp = meta.GetGraphType(i);

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

                nonNull++;

                ZipEntry 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");
                }


                NavGraph tmp = data.CreateGraph(tp);                //(NavGraph)System.Activator.CreateInstance(tp);

#if !ASTAR_NO_JSON
                String entryText = GetString(entry);

                JsonReader reader = new JsonReader(entryText, readerSettings);

                //NavGraph graph = tmp.Deserialize(reader);//reader.Deserialize<NavGraph>();
                reader.PopulateObject(ref tmp);
#else
                var mem = new MemoryStream();
                entry.Extract(mem);
                mem.Position = 0;
                var reader = new BinaryReader(mem);
                var ctx    = new GraphSerializationContext(reader, null, i);
                tmp.DeserializeSettings(ctx);
#endif

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

                //NavGraph graph = (NavGraph)JsonConvert.DeserializeObject (entryText,tp,settings);
            }

            NavGraph[] 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);

            //watch.Stop();
            //Debug.Log ((watch.ElapsedTicks*0.0001).ToString ("0.00"));
            //}
        }
Exemplo n.º 5
0
        /** 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);
        }