/** Serialize metadata about all graphs */ byte[] SerializeMeta() { if (graphs == null) { throw new System.Exception("No call to SerializeGraphs has been done"); } meta.version = AstarPath.Version; meta.graphs = graphs.Length; meta.guids = new List <string>(); meta.typeNames = new List <string>(); // For each graph, save the guid // of the graph and the type of it for (int i = 0; i < graphs.Length; i++) { if (graphs[i] != null) { meta.guids.Add(graphs[i].guid.ToString()); meta.typeNames.Add(graphs[i].GetType().FullName); } else { meta.guids.Add(null); meta.typeNames.Add(null); } } // Grab a cached string builder to avoid allocations var output = GetStringBuilder(); TinyJsonSerializer.Serialize(meta, output); return(encoding.GetBytes(output.ToString())); }
public byte[] Serialize(NavGraph graph) { StringBuilder stringBuilder = AstarSerializer.GetStringBuilder(); TinyJsonSerializer.Serialize(graph, stringBuilder); return(this.encoding.GetBytes(stringBuilder.ToString())); }
private byte[] SerializeMeta() { if (this.graphs == null) { throw new Exception("No call to SerializeGraphs has been done"); } this.meta.version = AstarPath.Version; this.meta.graphs = this.graphs.Length; this.meta.guids = new List <string>(); this.meta.typeNames = new List <string>(); for (int i = 0; i < this.graphs.Length; i++) { if (this.graphs[i] != null) { this.meta.guids.Add(this.graphs[i].guid.ToString()); this.meta.typeNames.Add(this.graphs[i].GetType().FullName); } else { this.meta.guids.Add(null); this.meta.typeNames.Add(null); } } StringBuilder stringBuilder = AstarSerializer.GetStringBuilder(); TinyJsonSerializer.Serialize(this.meta, stringBuilder); return(this.encoding.GetBytes(stringBuilder.ToString())); }
public void SerializeEditorSettings(GraphEditorBase[] editors) { if (editors == null || !settings.editorSettings) { return; } for (int i = 0; i < editors.Length; i++) { if (editors[i] == null) { return; } var output = GetStringBuilder(); TinyJsonSerializer.Serialize(editors[i], output); var bytes = encoding.GetBytes(output.ToString()); //Less or equal to 2 bytes means that nothing was saved (file is "{}") if (bytes.Length <= 2) { continue; } AddChecksum(bytes); zip.AddEntry("graph" + i + "_editor" + jsonExt, bytes); } }
/** Serializes the graph settings to JSON and returns the data */ public byte[] Serialize(NavGraph graph) { // Grab a cached string builder to avoid allocations var output = GetStringBuilder(); TinyJsonSerializer.Serialize(graph, output); return(encoding.GetBytes(output.ToString())); }
/** Serializes the graph settings to JSON and returns the data */ public byte[] Serialize(NavGraph graph) { // Grab a cached string builder to avoid allocations var output = GetStringBuilder(); TinyJsonSerializer.Serialize(graph, output); File.WriteAllText(Application.dataPath + "/graph.txt", output.ToString()); return(encoding.GetBytes(output.ToString())); }
public void SerializeEditorSettings(GraphEditorBase[] editors) { if (editors == null || !this.settings.editorSettings) { return; } for (int i = 0; i < editors.Length; i++) { if (editors[i] == null) { return; } StringBuilder stringBuilder = AstarSerializer.GetStringBuilder(); TinyJsonSerializer.Serialize(editors[i], stringBuilder); byte[] bytes = this.encoding.GetBytes(stringBuilder.ToString()); if (bytes.Length > 2) { this.AddChecksum(bytes); this.AddEntry("graph" + i + "_editor.json", bytes); } } }