コード例 #1
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Deserializes common info additively
		 * Common info is what is shared between the editor serialization and the runtime serializer.
		 * This is mostly everything except the graph inspectors which serialize some extra data in the editor
		 */
		public void DeserializeGraphsPartAdditive (AstarSerializer sr) {
			if (graphs == null) graphs = new NavGraph[0];
			
			var gr = new List<NavGraph>(graphs);

			// Set an offset so that the deserializer will load
			// the graphs with the correct graph indexes
			sr.SetGraphIndexOffset (gr.Count);

			gr.AddRange (sr.DeserializeGraphs ());
			graphs = gr.ToArray();
			
			//Assign correct graph indices. Issue #21
			for (int i=0;i<graphs.Length;i++) {
				if (graphs[i] == null) continue;
				graphs[i].GetNodes (node => {
					node.GraphIndex = (uint)i;
					return true;
				});
			}
			
			sr.DeserializeExtraInfo();
			sr.PostDeserialization();
			
			for (int i=0;i<graphs.Length;i++) {
				for (int j=i+1;j<graphs.Length;j++) {
					if (graphs[i] != null && graphs[j] != null && graphs[i].guid == graphs[j].guid) {
						Debug.LogWarning ("Guid Conflict when importing graphs additively. Imported graph will get a new Guid.\nThis message is (relatively) harmless.");
						graphs[i].guid = Guid.NewGuid ();
						break;
					}
				}
			}
		}
コード例 #2
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Deserializes graphs from the specified byte array additively.
		 * If an error ocurred, it will try to deserialize using the old deserializer.
		 * A warning will be logged if all deserializers failed.
		 * This function will add loaded graphs to the current ones
		  */
		public void DeserializeGraphsAdditive (byte[] bytes) {
			
			AstarPath.active.BlockUntilPathQueueBlocked();
			
			try {
				if (bytes != null) {
					var sr = new AstarSerializer(this);
					
					if (sr.OpenDeserialize(bytes)) {
						DeserializeGraphsPartAdditive (sr);
						sr.CloseDeserialize();
					} else {
						Debug.Log ("Invalid data file (cannot read zip).");
					}
				} else {
					throw new System.ArgumentNullException ("bytes");
				}
				active.VerifyIntegrity ();
			} catch (System.Exception e) {
				Debug.LogWarning ("Caught exception while deserializing data.\n"+e);
			}
			
		}
コード例 #3
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Deserializes common info.
		 * Common info is what is shared between the editor serialization and the runtime serializer.
		 * This is mostly everything except the graph inspectors which serialize some extra data in the editor
		 */
		public void DeserializeGraphsPart (AstarSerializer sr) {
			ClearGraphs ();
			graphs = sr.DeserializeGraphs ();

			sr.DeserializeExtraInfo();

			//Assign correct graph indices.
			for (int i=0;i<graphs.Length;i++) {
				if (graphs[i] == null) continue;
				graphs[i].GetNodes (node => {
					node.GraphIndex = (uint)i;
					return true;
				});
			}

			sr.PostDeserialization();
		}
コード例 #4
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Deserializes graphs from the specified byte array.
		 * If an error occured, it will try to deserialize using the old deserializer.
		 * A warning will be logged if all deserializers failed.
		  */
		public void DeserializeGraphs (byte[] bytes) {
			
			AstarPath.active.BlockUntilPathQueueBlocked();
			
			try {
				if (bytes != null) {
					var sr = new AstarSerializer(this);
					
					if (sr.OpenDeserialize(bytes)) {
						DeserializeGraphsPart (sr);
						sr.CloseDeserialize();
						UpdateShortcuts ();
					} else {
						Debug.Log ("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
					}
				} else {
					throw new System.ArgumentNullException ("bytes");
				}
				active.VerifyIntegrity ();
			} catch (System.Exception e) {
				Debug.LogWarning ("Caught exception while deserializing data.\n"+e);
				data_backup = bytes;
			}
			
		}
コード例 #5
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Serializes common info to the serializer.
		 * Common info is what is shared between the editor serialization and the runtime serializer.
		 * This is mostly everything except the graph inspectors which serialize some extra data in the editor
		 */
		public void SerializeGraphsPart (AstarSerializer sr) {
			sr.SerializeGraphs(graphs);
			sr.SerializeNodes();
			sr.SerializeExtraInfo();
		}
コード例 #6
0
ファイル: AstarData.cs プロジェクト: luukholleman/Airchitect
		/** Main serializer function.
		 * Serializes all graphs to a byte array
		  * A similar function exists in the AstarPathEditor.cs script to save additional info */
		public byte[] SerializeGraphs (SerializeSettings settings, out uint checksum) {
			
			AstarPath.active.BlockUntilPathQueueBlocked();
			
			var sr = new AstarSerializer(this, settings);
			sr.OpenSerialize();
			SerializeGraphsPart (sr);
			byte[] bytes = sr.CloseSerialize();
			checksum = sr.GetChecksum ();
	#if ASTARDEBUG
			Debug.Log ("Got a whole bunch of data, "+bytes.Length+" bytes");
	#endif
			return bytes;
		}
コード例 #7
0
        void DeserializeGraphs (byte[] bytes) {

            AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (force => {
                                                                                    var sr = new AstarSerializer(script.astarData);
                                                                                    if (sr.OpenDeserialize(bytes)) {
                                                                                        script.astarData.DeserializeGraphsPart (sr);

                                                                                        // Make sure every graph has a graph editor
                                                                                        CheckGraphEditors ();
                                                                                        sr.DeserializeEditorSettings (graphEditors);

                                                                                        sr.CloseDeserialize();
                                                                                    } else {
                                                                                        Debug.LogWarning ("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
                                                                                        // Make sure every graph has a graph editor
                                                                                        CheckGraphEditors ();
                                                                                    }
                                                                                    return true;
            }));

            // Make sure the above work item is run directly
            AstarPath.active.FlushWorkItems();
        }
コード例 #8
0
        public byte[] SerializeGraphs (SerializeSettings settings, out uint checksum) {
            byte[] bytes = null;
            uint ch = 0;

            // Add a work item since we cannot be sure that pathfinding (or graph updates)
            // is not running at the same time
            AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (force => {
                                                                                    var sr = new AstarSerializer(script.astarData, settings);
                                                                                    sr.OpenSerialize();
                                                                                    script.astarData.SerializeGraphsPart (sr);
                                                                                    sr.SerializeEditorSettings (graphEditors);
                                                                                    bytes = sr.CloseSerialize();
                                                                                    ch = sr.GetChecksum ();
#if ASTARDEBUG
			Debug.Log ("Got a whole bunch of data, "+bytes.Length+" bytes");
	#endif
                                                                                    return true;
            }));

            // Make sure the above work item is executed immediately
            AstarPath.active.FlushWorkItems();
            checksum = ch;
            return bytes;
        }