Пример #1
0
		public static void DeserializeVoxelAreaData (byte[] bytes, VoxelArea target) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			stream.Write(bytes,0,bytes.Length);
			stream.Position = 0;
			zip = Ionic.Zip.ZipFile.Read(stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			
			zip["data"].Extract (stream2);
			stream2.Position = 0;
			System.IO.BinaryReader reader = new System.IO.BinaryReader(stream2);
			
			int width = reader.ReadInt32();
			int depth = reader.ReadInt32();
			if (target.width != width) throw new System.ArgumentException ("target VoxelArea has a different width than the data ("+target.width + " != " + width + ")");
			if (target.depth != depth) throw new System.ArgumentException ("target VoxelArea has a different depth than the data ("+target.depth + " != " + depth + ")");
			LinkedVoxelSpan[] spans = new LinkedVoxelSpan[reader.ReadInt32()];
			
			for (int i=0;i<spans.Length;i++) {
				spans[i].area = reader.ReadInt32();
				spans[i].bottom = reader.ReadUInt32();
				spans[i].next = reader.ReadInt32();
				spans[i].top = reader.ReadUInt32();
			}
			target.linkedSpans = spans;
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
Пример #2
0
		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
		}
Пример #3
0
		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
Пример #4
0
		public void OpenSerialize () {
			zip = new ZipFile();
			zip.AlternateEncoding = System.Text.Encoding.UTF8;
			zip.AlternateEncodingUsage = ZipOption.Always;
			
			writerSettings = new JsonWriterSettings();
			writerSettings.AddTypeConverter (new VectorConverter());
			writerSettings.AddTypeConverter (new BoundsConverter());
			writerSettings.AddTypeConverter (new LayerMaskConverter());
			writerSettings.AddTypeConverter (new MatrixConverter());
			writerSettings.AddTypeConverter (new GuidConverter());
			writerSettings.AddTypeConverter (new UnityObjectConverter());
			
			//writerSettings.DebugMode = true;
			writerSettings.PrettyPrint = settings.prettyPrint;
			
			meta = new GraphMeta();
		}
Пример #5
0
		public void CloseDeserialize () {
			str.Close();
			zip.Dispose();
			zip = null;
			str = null;
		}
Пример #6
0
		public bool OpenDeserialize (byte[] bytes) {
			readerSettings = new JsonReaderSettings();
			readerSettings.AddTypeConverter (new VectorConverter());
			readerSettings.AddTypeConverter (new BoundsConverter());
			readerSettings.AddTypeConverter (new LayerMaskConverter());
			readerSettings.AddTypeConverter (new MatrixConverter());
			readerSettings.AddTypeConverter (new GuidConverter());
			readerSettings.AddTypeConverter (new UnityObjectConverter());
			
			str = new MemoryStream();
			str.Write(bytes,0,bytes.Length);
			str.Position = 0;
			try {
				zip = ZipFile.Read(str);
			} catch (ZipException e) {
				//Catches exceptions when an invalid zip file is found
				Debug.LogWarning ("Caught exception when loading from zip\n"+e);
				str.Close();
				return false;
			}
			meta = DeserializeMeta (zip["meta"+jsonExt]);
			
			if (meta.version > AstarPath.Version) {
				Debug.LogWarning ("Trying to load data from a newer version of the A* Pathfinding Project\nCurrent version: "+AstarPath.Version+" Data version: "+meta.version);
			} else if (meta.version < AstarPath.Version) {
				Debug.LogWarning ("Trying to load data from an older version of the A* Pathfinding Project\nCurrent version: "+AstarPath.Version+" Data version: "+meta.version
					+ "\nThis is usually fine, it just means you have upgraded to a new version.\nHowever node data (not settings) can get corrupted between versions, so it is recommended" +
						"to recalculate any caches (those for faster startup) and resave any files. Even if it seems to load fine, it might cause subtle bugs.\n");
			}
			return true;
		}
Пример #7
0
		public byte[] CloseSerialize () {
			byte[] bytes = SerializeMeta ();
			
			AddChecksum (bytes);
			zip.AddEntry("meta"+jsonExt,bytes);
			
			MemoryStream output = new MemoryStream();
    		zip.Save(output);
			output.Close();
			bytes = output.ToArray();
			
#if ASTARDEBUG
			FileStream fs = new FileStream("output.zip",FileMode.Create);
			fs.Write(bytes,0,bytes.Length);
			fs.Close();
#endif
			
			zip.Dispose();
			
			zip = null;
			return bytes;
		}
Пример #8
0
		public byte[] CloseSerialize () {
			byte[] bytes = SerializeMeta ();
			
			AddChecksum (bytes);
			zip.AddEntry("meta"+jsonExt,bytes);
			
			MemoryStream output = new MemoryStream();
    		zip.Save(output);
			bytes = output.ToArray();
			output.Dispose();
			
			
			zip.Dispose();
			
			zip = null;
			return bytes;
		}