本文整理汇总了C#中JsonReader.PopulateObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.PopulateObject方法的具体用法?C# JsonReader.PopulateObject怎么用?C# JsonReader.PopulateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonReader
的用法示例。
在下文中一共展示了JsonReader.PopulateObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeEditorSettings
/** Deserializes graph editor settings.
* For future compatibility this method does not assume that the \a graphEditors array matches the #graphs array in order and/or count.
* It searches for a matching graph (matching if graphEditor.target == graph) for every graph editor.
* Multiple graph editors should not refer to the same graph.\n
* \note Stored in files named "graph#_editor.json" where # is the graph number.
*/
public void DeserializeEditorSettings(GraphEditorBase[] graphEditors)
{
if (graphEditors == null) return;
for (int i=0;i<graphEditors.Length;i++) {
if (graphEditors[i] == null) continue;
for (int j=0;j<graphs.Length;j++) {
if (graphs[j] == null || graphEditors[i].target != graphs[j]) continue;
ZipEntry entry = zip["graph"+j+"_editor"+jsonExt];
if (entry == null) continue;
string entryText = GetString (entry);
JsonReader reader = new JsonReader(entryText,readerSettings);
reader.PopulateObject (graphEditors[i]);
break;
}
}
}
示例2: DeserializeGraphs
/** 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"));
//}
}
示例3: DeserializeGraphs
/** 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;
}
示例4: DeserializeGraphs
/** 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"));
//}
}
示例5: DeserializeEditorSettings
//#if UNITY_EDITOR
/** Deserializes graph editor settings.
* For future compatibility this method does not assume that the \a graphEditors array matches the #graphs array in order and/or count.
* It searches for a matching graph (matching if graphEditor.target == graph) for every graph editor.
* Multiple graph editors should not refer to the same graph.\n
* \note Stored in files named "graph#_editor.json" where # is the graph number.
*/
public void DeserializeEditorSettings (GraphEditorBase[] graphEditors) {
#if !ASTAR_NO_JSON
if (graphEditors == null) return;
for (var i=0;i<graphEditors.Length;i++) {
if (graphEditors[i] == null) continue;
for (var j=0;j<graphs.Length;j++) {
if (graphs[j] == null || graphEditors[i].target != graphs[j]) continue;
var entry = zip["graph"+j+"_editor"+jsonExt];
if (entry == null) continue;
var entryText = GetString (entry);
var reader = new JsonReader(entryText,readerSettings);
var graphEditor = graphEditors[i];
reader.PopulateObject (ref graphEditor);
graphEditors[i] = graphEditor;
break;
}
}
#endif
}
示例6: DeserializeGraph
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;
}