Exemplo n.º 1
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];

            for (int i = 0; i < meta.graphs; i++)
            {
                Type     tp    = meta.GetGraphType(i);
                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"));
            //}
        }