Ejemplo n.º 1
0
 public void SaveConfig(string path, Dictionary <string, object> config)
 {
     using (var jr = new Json.JsonWriter(path))
     {
         jr.Settings.PrettyPrint = true;
         jr.Write(config);
     }
 }
Ejemplo n.º 2
0
        public static string ToJSONstring(this object obj, int recursiondepth)
        {
            var settings = new jsonfx.JsonWriterSettings();

            //settings.PrettyPrint = true;

            System.Text.StringBuilder output = new System.Text.StringBuilder();
            var writer = new jsonfx.JsonWriter(output, settings);

            writer.Settings.HandleCyclicReferences = true;
            writer.Settings.MaxDepth = recursiondepth;
            writer.Write(obj);
            return(output.ToString());
        }
Ejemplo n.º 3
0
        public static string ToJSONstring(this object obj)
        {
            var settings = new jsonfx.JsonWriterSettings();

            //settings.PrettyPrint = true;

            System.Text.StringBuilder output = new System.Text.StringBuilder();
            var writer = new jsonfx.JsonWriter(output, settings);

            //writer.Settings.HandleCyclicReferences = true;
            if (obj.GetType() == typeof(VariableReference))
            {
                Debug.Log(((VariableReference)obj).VariableName);
            }
            writer.Write(obj);
            return(output.ToString());
        }
Ejemplo n.º 4
0
        public void SerializeEditorSettings(GraphEditorBase[] editors)
        {
            if (editors == null || !settings.editorSettings) return;

            for (int i=0;i<editors.Length;i++) {
                if (editors[i] == null) return;

                System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
                JsonWriter writer = new JsonWriter (output,writerSettings);
                writer.Write (editors[i]);

                byte[] 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);
            }
        }
Ejemplo n.º 5
0
        /** Serialize metadata about alll graphs */
        private byte[] SerializeMeta()
        {
            meta.version = AstarPath.Version;
            meta.graphs = data.graphs.Length;
            meta.guids = new string[data.graphs.Length];
            meta.typeNames = new string[data.graphs.Length];
            meta.nodeCounts = new int[data.graphs.Length];
            //meta.settings = settings;

            for (int i=0;i<data.graphs.Length;i++) {
                meta.guids[i] = data.graphs[i].guid.ToString();
                meta.typeNames[i] = data.graphs[i].GetType().FullName;

                meta.nodeCounts[i] = data.graphs[i].nodes==null?0:data.graphs[i].nodes.Length;
            }

            System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
            JsonWriter writer = new JsonWriter (output,writerSettings);
            writer.Write (meta);

            return encoding.GetBytes (output.ToString());
        }
Ejemplo n.º 6
0
        public void SerializeUserConnections(UserConnection[] conns)
        {
            if (conns == null) conns = new UserConnection[0];

            System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
            JsonWriter writer = new JsonWriter (output,writerSettings);
            writer.Write (conns);

            byte[] bytes = encoding.GetBytes (output.ToString());
            output = null;

            //If length is <= 2 that means nothing was serialized (file is "[]")
            if (bytes.Length <= 2) return;

            AddChecksum (bytes);
            zip.AddEntry ("connections"+jsonExt,bytes);
        }
Ejemplo n.º 7
0
        /** Serializes the graph settings to JSON and returns the data */
        public byte[] Serialize(NavGraph graph)
        {
            System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
            JsonWriter writer = new JsonWriter (output,writerSettings);
            writer.Write (graph);

            return encoding.GetBytes (output.ToString());
        }
		public void Write (JsonWriter writer, Type type, object value) {
			Dictionary<string,object> dict = WriteJson (type,value);
			writer.Write (dict);
		}
Ejemplo n.º 9
0
		/** Serializes the graph settings to JSON and returns the data */
		public byte[] Serialize (NavGraph graph) {
#if !ASTAR_NO_JSON
			// Grab a cached string builder to avoid allocations
			var output = GetStringBuilder ();
			var writer = new JsonWriter (output,writerSettings);
			writer.Write (graph);
			
			return encoding.GetBytes (output.ToString());
#else
			var mem = new System.IO.MemoryStream();
			var writer = new System.IO.BinaryWriter(mem);
			var ctx = new GraphSerializationContext (writer);
			graph.SerializeSettings (ctx);
			return mem.ToArray();
#endif
		}
Ejemplo n.º 10
0
		/** Serialize metadata about all graphs */
		byte[] SerializeMeta () {

			meta.version = AstarPath.Version;
			meta.graphs = data.graphs.Length;
			meta.guids = new string[data.graphs.Length];
			meta.typeNames = new string[data.graphs.Length];
			meta.nodeCounts = new int[data.graphs.Length];

			// For each graph, save the guid
			// of the graph and the type of it
			for (int i=0;i<data.graphs.Length;i++) {
				if (data.graphs[i] == null) continue;
				
				meta.guids[i] = data.graphs[i].guid.ToString();
				meta.typeNames[i] = data.graphs[i].GetType().FullName;
			}

#if !ASTAR_NO_JSON
			// Grab a cached string builder to avoid allocations
			var output = GetStringBuilder ();
			var writer = new JsonWriter (output,writerSettings);
			writer.Write (meta);
			
			return encoding.GetBytes (output.ToString());
#else
			// Serialize the metadata without using json for compatibility
			var mem = new System.IO.MemoryStream();
			var writer = new System.IO.BinaryWriter(mem);
			writer.Write ( "A*" ); // Magic string
			writer.Write (meta.version.Major);
			writer.Write (meta.version.Minor);
			writer.Write (meta.version.Build);
			writer.Write (meta.version.Revision);
			writer.Write (meta.graphs);

			writer.Write (meta.guids.Length);
			for ( int i = 0; i < meta.guids.Length; i++ ) writer.Write ( meta.guids[i] ?? "" );

			writer.Write (meta.typeNames.Length);
			for ( int i = 0; i < meta.typeNames.Length; i++ ) writer.Write ( meta.typeNames[i] ?? "" );

			writer.Write (meta.nodeCounts.Length);
			for ( int i = 0; i < meta.nodeCounts.Length; i++ ) writer.Write ( meta.nodeCounts[i] );

			return mem.ToArray();
#endif
		}
Ejemplo n.º 11
0
		/** Serialize metadata about alll graphs */
		private byte[] SerializeMeta () {
			
			meta.version = AstarPath.Version;
			meta.graphs = data.graphs.Length;
			meta.guids = new string[data.graphs.Length];
			meta.typeNames = new string[data.graphs.Length];
			meta.nodeCounts = new int[data.graphs.Length];
			//meta.settings = settings;
			
			for (int i=0;i<data.graphs.Length;i++) {
				if (data.graphs[i] == null) continue;
				
				meta.guids[i] = data.graphs[i].guid.ToString();
				meta.typeNames[i] = data.graphs[i].GetType().FullName;
				
				//meta.nodeCounts[i] = data.graphs[i].nodes==null?0:data.graphs[i].nodes.Length;
			}

#if !ASTAR_NO_JSON
			System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
			JsonWriter writer = new JsonWriter (output,writerSettings);
			writer.Write (meta);
			
			return encoding.GetBytes (output.ToString());
#else
			var mem = new System.IO.MemoryStream();
			var writer = new System.IO.BinaryWriter(mem);
			writer.Write ( "A*" ); // Magic string
			writer.Write (meta.version.Major);
			writer.Write (meta.version.Minor);
			writer.Write (meta.version.Build);
			writer.Write (meta.version.Revision);
			writer.Write (meta.graphs);
			writer.Write (meta.guids.Length);
			for ( int i = 0; i < meta.guids.Length; i++ ) writer.Write ( meta.guids[i] );
			writer.Write (meta.typeNames.Length);
			for ( int i = 0; i < meta.typeNames.Length; i++ ) writer.Write ( meta.typeNames[i] );
			writer.Write (meta.nodeCounts.Length);
			for ( int i = 0; i < meta.nodeCounts.Length; i++ ) writer.Write ( meta.nodeCounts[i] );
			return mem.ToArray();
#endif
		}
Ejemplo n.º 12
0
		/// <summary>
		/// A helper method for serializing an object to JSON
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static string Serialize(object value)
		{
			StringBuilder output = new StringBuilder();

			using (JsonWriter writer = new JsonWriter(output))
			{
				writer.Write(value);
			}

			return output.ToString();
		}
Ejemplo n.º 13
0
        public void Write(JsonWriter writer, Type type, object value)
        {
            Dictionary <string, object> dict = WriteJson(type, value);

            writer.Write(dict);
        }
Ejemplo n.º 14
0
        public void Write(JsonWriter writer, Type type, object value)
        {
            DictType dict = WriteJson(type, value);

            writer.Write(dict);
        }