/** Deserializes serialization info. Deserializes Version, mask and #loadedGraphGuids * \see OpenDeserialize */ public AstarSerializer DeserializeSerializationInfo() { if (!MoveToAnchor("SerializerSettings")) { throw (new System.NullReferenceException("Anchor SerializerSettings was not found in the data")); } BinaryReader stream = readerStream; System.Version astarVersion = null; try { astarVersion = new Version(stream.ReadString()); } catch (Exception e) { Debug.LogError("Couldn't parse A* version "); error = SerializerError.WrongVersion; throw new System.FormatException("Couldn't parse A* version", e); } //System.Version astarVersion2 = AstarPath.Version; AstarSerializer returnSerializer = this; if (!IgnoreVersionDifferences) { if (astarVersion > AstarPath.Version) { Debug.LogError("Loading graph saved with a newer version of the A* Pathfinding Project, trying to load, but you might get errors.\nFile version: " + astarVersion + " Current A* version: " + AstarPath.Version); //error = SerializerError.WrongVersion; //return; } else if (astarVersion != AstarPath.Version) { Debug.LogWarning("Loading graphs saved with an older version of the A* Pathfinding Project, trying to load.\nFile version: " + astarVersion + " Current A* version: " + AstarPath.Version); //Copy this serializer's loaded values to the new serializer returnSerializer = new AstarSerializer3_01(active); returnSerializer.readerStream = readerStream; returnSerializer.anchors = anchors; } } int count = stream.ReadInt32(); //@Fix - Look up existing graph first returnSerializer.loadedGraphGuids = new string[count]; for (int i = 0; i < count; i++) { returnSerializer.loadedGraphGuids[i] = stream.ReadString(); //loadedGraphGuids[i] = i; } returnSerializer.mask = stream.ReadInt32(); return(returnSerializer); }
public byte[] LoadFromFile(string path) { if (!File.Exists(path)) { error = SerializerError.DoesNotExist; Debug.LogError("File does not exist : " + path); return(new byte[0]); } FileStream fs = File.Open(path, FileMode.Open); /*int b1 = fs.ReadByte (); * int b2 = fs.ReadByte (); * if (b1 != 0x3A || b2 != 0x44) { * Debug.LogWarning ("Magic Numbers did not match - The file is probably corrupt\nThe magic numbers in the file were "+(char)b1+" and "+(char)b2+" ("+b1+", "+b2+")"); * error = SerializerError.WrongMagic; * return null; * }*/ byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); return(bytes); }
public byte[] LoadFromFile(string path) { if (!File.Exists (path)) { error = SerializerError.DoesNotExist; Debug.LogError ("File does not exist : "+path); return new byte[0]; } FileStream fs = File.Open (path, FileMode.Open); /*int b1 = fs.ReadByte (); int b2 = fs.ReadByte (); if (b1 != 0x3A || b2 != 0x44) { Debug.LogWarning ("Magic Numbers did not match - The file is probably corrupt\nThe magic numbers in the file were "+(char)b1+" and "+(char)b2+" ("+b1+", "+b2+")"); error = SerializerError.WrongMagic; return null; }*/ byte[] bytes = new byte[fs.Length]; fs.Read (bytes,0,bytes.Length); fs.Close (); return bytes; }
/** Deserializes serialization info. Deserializes Version, mask and #loadedGraphGuids * \see OpenDeserialize */ public AstarSerializer DeserializeSerializationInfo() { if (!MoveToAnchor ("SerializerSettings")) { throw (new System.NullReferenceException ("Anchor SerializerSettings was not found in the data")); } BinaryReader stream = readerStream; System.Version astarVersion = null; try { astarVersion = new Version (stream.ReadString ()); } catch (Exception e) { Debug.LogError ("Couldn't parse A* version "); error = SerializerError.WrongVersion; throw new System.FormatException ("Couldn't parse A* version",e); } //System.Version astarVersion2 = AstarPath.Version; AstarSerializer returnSerializer = this; if (!IgnoreVersionDifferences) { if (astarVersion > AstarPath.Version) { Debug.LogError ("Loading graph saved with a newer version of the A* Pathfinding Project, trying to load, but you might get errors.\nFile version: "+astarVersion+" Current A* version: "+AstarPath.Version); //error = SerializerError.WrongVersion; //return; } else if (astarVersion != AstarPath.Version) { Debug.LogWarning ("Loading graphs saved with an older version of the A* Pathfinding Project, trying to load.\nFile version: "+astarVersion+" Current A* version: "+AstarPath.Version); //Select the appropriate deserializer if (astarVersion < new Version (3,0,4)) { returnSerializer = new AstarSerializer3_01 (active); } else if (astarVersion < new Version (3,0,5)) { returnSerializer = new AstarSerializer3_04 (active); } else if (astarVersion < new Version (3,0,6)) { returnSerializer = new AstarSerializer3_05 (active); } //Copy this serializer's loaded values to the new serializer returnSerializer.readerStream = readerStream; returnSerializer.anchors = anchors; } } int count = stream.ReadInt32 (); //@Fix - Look up existing graph first returnSerializer.loadedGraphGuids = new string[count]; for (int i=0;i<count;i++) { returnSerializer.loadedGraphGuids[i] = stream.ReadString (); //loadedGraphGuids[i] = i; } returnSerializer.mask = stream.ReadInt32 (); return returnSerializer; }