Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /** 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;
                }
            }
        }
Esempio n. 3
0
		/** 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 (int i = 0; i < graphEditors.Length; i++) {
				if (graphEditors[i] == null) continue;
				for (int j = 0; j < graphs.Length; j++) {
					if (graphEditors[i].target != graphs[j]) continue;

					var zipIndex = graphIndexInZip[graphs[j]];
					ZipEntry entry = zip["graph"+zipIndex+"_editor"+jsonExt];
					if (entry == null) continue;

					string entryText = GetString(entry);

					var reader = new JsonReader(entryText, readerSettings);
					GraphEditorBase graphEditor = graphEditors[i];
					reader.PopulateObject(ref graphEditor);
					graphEditors[i] = graphEditor;
					break;
				}
			}
#endif
		}