Ejemplo n.º 1
0
        public void OpenSerialize()
        {
            Debug.LogError("OpenSerialize");
#if ASTAR_NO_JSON
            Debug.LogError("FuckNoJson");
#endif
            // Create a new zip file, here we will store all the data
            zip = new ZipFile();
            zip.AlternateEncoding      = System.Text.Encoding.UTF8;
            zip.AlternateEncodingUsage = ZipOption.Always;

#if !ASTAR_NO_JSON
            // Add some converters so that we can serialize some Unity types
            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.PrettyPrint = settings.prettyPrint;
#endif
            meta = new GraphMeta();
        }
Ejemplo n.º 2
0
 public void OpenSerialize()
 {
     this.zip = new ZipFile();
     this.zip.AlternateEncoding      = Encoding.get_UTF8();
     this.zip.AlternateEncodingUsage = ZipOption.Always;
     this.meta = new GraphMeta();
 }
Ejemplo n.º 3
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");
            }
            return(true);
        }
Ejemplo n.º 4
0
 public GraphSerializationContext(BinaryReader reader, GraphNode[] id2NodeMapping, uint graphIndex, GraphMeta meta)
 {
     this.reader         = reader;
     this.id2NodeMapping = id2NodeMapping;
     this.graphIndex     = graphIndex;
     this.meta           = meta;
 }
Ejemplo n.º 5
0
        private GraphMeta DeserializeMeta(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new Exception("No metadata found in serialized data.");
            }
            GraphMeta    graphMeta    = new GraphMeta();
            MemoryStream memoryStream = new MemoryStream();

            entry.Extract(memoryStream);
            memoryStream.set_Position(0L);
            BinaryReader binaryReader = new BinaryReader(memoryStream);

            if (binaryReader.ReadString() != "A*")
            {
                throw new Exception("Invalid magic number in saved data");
            }
            int num  = binaryReader.ReadInt32();
            int num2 = binaryReader.ReadInt32();
            int num3 = binaryReader.ReadInt32();
            int num4 = binaryReader.ReadInt32();

            if (num < 0)
            {
                graphMeta.version = new Version(0, 0);
            }
            else if (num2 < 0)
            {
                graphMeta.version = new Version(num, 0);
            }
            else if (num3 < 0)
            {
                graphMeta.version = new Version(num, num2);
            }
            else if (num4 < 0)
            {
                graphMeta.version = new Version(num, num2, num3);
            }
            else
            {
                graphMeta.version = new Version(num, num2, num3, num4);
            }
            graphMeta.graphs = binaryReader.ReadInt32();
            graphMeta.guids  = new string[binaryReader.ReadInt32()];
            for (int i = 0; i < graphMeta.guids.Length; i++)
            {
                graphMeta.guids[i] = binaryReader.ReadString();
            }
            graphMeta.typeNames = new string[binaryReader.ReadInt32()];
            for (int j = 0; j < graphMeta.typeNames.Length; j++)
            {
                graphMeta.typeNames[j] = binaryReader.ReadString();
            }
            graphMeta.nodeCounts = new int[binaryReader.ReadInt32()];
            for (int k = 0; k < graphMeta.nodeCounts.Length; k++)
            {
                graphMeta.nodeCounts[k] = binaryReader.ReadInt32();
            }
            return(graphMeta);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
 public void OpenSerialize()
 {
     // Create a new zip file, here we will store all the data
     zip = new ZipFile();
     zip.AlternateEncoding      = System.Text.Encoding.UTF8;
     zip.AlternateEncodingUsage = ZipOption.Always;
     meta = new GraphMeta();
 }
Ejemplo n.º 8
0
        private GraphMeta DeserializeBinaryMeta(ZipEntry entry)
        {
            var meta = new GraphMeta();

            var reader = GetBinaryReader(entry);

            if (reader.ReadString() != "A*")
            {
                throw new System.Exception("Invalid magic number in saved data");
            }
            int major    = reader.ReadInt32();
            int minor    = reader.ReadInt32();
            int build    = reader.ReadInt32();
            int revision = reader.ReadInt32();

            // Required because when saving a version with a field not set, it will save it as -1
            // and then the Version constructor will throw an exception (which we do not want)
            if (major < 0)
            {
                meta.version = new Version(0, 0);
            }
            else if (minor < 0)
            {
                meta.version = new Version(major, 0);
            }
            else if (build < 0)
            {
                meta.version = new Version(major, minor);
            }
            else if (revision < 0)
            {
                meta.version = new Version(major, minor, build);
            }
            else
            {
                meta.version = new Version(major, minor, build, revision);
            }

            meta.graphs = reader.ReadInt32();

            meta.guids = new List <string>();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                meta.guids.Add(reader.ReadString());
            }

            meta.typeNames = new List <string>();
            count          = reader.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                meta.typeNames.Add(reader.ReadString());
            }
            reader.Close();

            return(meta);
        }
Ejemplo n.º 9
0
        public bool OpenDeserialize(byte[] bytes)
        {
            // Copy the bytes to a stream
            zipStream = new MemoryStream();
            zipStream.Write(bytes, 0, bytes.Length);
            zipStream.Position = 0;
            try
            {
#if NETFX_CORE
                zip = new ZipFile(zipStream);
#else
                zip = ZipFile.Read(zipStream);
#endif
            }
            catch (Exception e)
            {
                // Catches exceptions when an invalid zip file is found
                Debug.LogError("Caught exception when loading from zip\n" + e);

                zipStream.Dispose();
                return(false);
            }

            if (ContainsEntry("meta" + jsonExt))
            {
                meta = DeserializeMeta(GetEntry("meta" + jsonExt));
            }
            else if (ContainsEntry("meta" + binaryExt))
            {
                meta = DeserializeBinaryMeta(GetEntry("meta" + binaryExt));
            }
            else
            {
                throw new Exception("No metadata found in serialized data.");
            }

            if (FullyDefinedVersion(meta.version) > FullyDefinedVersion(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 +
                    "\nThis is usually fine as the stored data is usually backwards and forwards compatible." +
                    "\nHowever node data (not settings) can get corrupted between versions (even though I try my best to keep compatibility), 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");
            }
            else if (FullyDefinedVersion(meta.version) < FullyDefinedVersion(AstarPath.Version))
            {
                Debug.LogWarning("Upgrading serialized pathfinding data from version " + meta.version + " to " +
                                 AstarPath.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 (even though I try my best to keep compatibility), 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);
        }
Ejemplo n.º 10
0
        public void OpenSerialize()
        {
            // Create a new zip file, here we will store all the data
            zipStream = new MemoryStream();
#if NETFX_CORE
            zip = new ZipFile(zipStream, System.IO.Compression.ZipArchiveMode.Create);
#else
            zip = new ZipFile();
            zip.AlternateEncoding      = System.Text.Encoding.UTF8;
            zip.AlternateEncodingUsage = ZipOption.Always;
#endif
            meta = new GraphMeta();
        }
Ejemplo n.º 11
0
        private GraphMeta DeserializeBinaryMeta(ZipEntry entry)
        {
            GraphMeta    graphMeta    = new GraphMeta();
            BinaryReader binaryReader = AstarSerializer.GetBinaryReader(entry);

            if (binaryReader.ReadString() != "A*")
            {
                throw new Exception("Invalid magic number in saved data");
            }
            int num  = binaryReader.ReadInt32();
            int num2 = binaryReader.ReadInt32();
            int num3 = binaryReader.ReadInt32();
            int num4 = binaryReader.ReadInt32();

            if (num < 0)
            {
                graphMeta.version = new Version(0, 0);
            }
            else if (num2 < 0)
            {
                graphMeta.version = new Version(num, 0);
            }
            else if (num3 < 0)
            {
                graphMeta.version = new Version(num, num2);
            }
            else if (num4 < 0)
            {
                graphMeta.version = new Version(num, num2, num3);
            }
            else
            {
                graphMeta.version = new Version(num, num2, num3, num4);
            }
            graphMeta.graphs = binaryReader.ReadInt32();
            graphMeta.guids  = new List <string>();
            int num5 = binaryReader.ReadInt32();

            for (int i = 0; i < num5; i++)
            {
                graphMeta.guids.Add(binaryReader.ReadString());
            }
            graphMeta.typeNames = new List <string>();
            num5 = binaryReader.ReadInt32();
            for (int j = 0; j < num5; j++)
            {
                graphMeta.typeNames.Add(binaryReader.ReadString());
            }
            return(graphMeta);
        }
Ejemplo n.º 12
0
 public void OpenSerialize()
 {
     this.zip = new ZipFile();
     this.zip.AlternateEncoding      = Encoding.UTF8;
     this.zip.AlternateEncodingUsage = ZipOption.Always;
     this.writerSettings             = new JsonWriterSettings();
     this.writerSettings.AddTypeConverter(new VectorConverter());
     this.writerSettings.AddTypeConverter(new BoundsConverter());
     this.writerSettings.AddTypeConverter(new LayerMaskConverter());
     this.writerSettings.AddTypeConverter(new MatrixConverter());
     this.writerSettings.AddTypeConverter(new GuidConverter());
     this.writerSettings.AddTypeConverter(new UnityObjectConverter());
     this.writerSettings.PrettyPrint = this.settings.prettyPrint;
     this.meta = new GraphMeta();
 }
Ejemplo n.º 13
0
 public bool OpenDeserialize(byte[] bytes)
 {
     this.readerSettings = new JsonReaderSettings();
     this.readerSettings.AddTypeConverter(new VectorConverter());
     this.readerSettings.AddTypeConverter(new BoundsConverter());
     this.readerSettings.AddTypeConverter(new LayerMaskConverter());
     this.readerSettings.AddTypeConverter(new MatrixConverter());
     this.readerSettings.AddTypeConverter(new GuidConverter());
     this.readerSettings.AddTypeConverter(new UnityObjectConverter());
     this.zipStream = new MemoryStream();
     this.zipStream.Write(bytes, 0, bytes.Length);
     this.zipStream.Position = 0L;
     try
     {
         this.zip = ZipFile.Read(this.zipStream);
     }
     catch (Exception arg)
     {
         Debug.LogError("Caught exception when loading from zip\n" + arg);
         this.zipStream.Dispose();
         return(false);
     }
     this.meta = this.DeserializeMeta(this.zip["meta.json"]);
     if (AstarSerializer.FullyDefinedVersion(this.meta.version) > AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from a newer version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.meta.version,
             "\nThis is usually fine as the stored data is usually backwards and forwards compatible.\nHowever node data (not settings) can get corrupted between versions (even though I try my best to keep compatibility), 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"
         }));
     }
     else if (AstarSerializer.FullyDefinedVersion(this.meta.version) < AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from an older version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.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 (even though I try my best to keep compatibility), 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);
 }
Ejemplo n.º 14
0
        private GraphMeta DeserializeMeta(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new System.Exception("No metadata found in serialized data.");
            }

#if !ASTAR_NO_JSON
            string s = GetString(entry);

            JsonReader reader = new JsonReader(s, readerSettings);
            return((GraphMeta)reader.Deserialize(typeof(GraphMeta)));

            //JsonConvert.DeserializeObject<GraphMeta>(s,settings);
#else
            var meta = new GraphMeta();

            var mem = new System.IO.MemoryStream();
            entry.Extract(mem);
            mem.Position = 0;
            var reader = new System.IO.BinaryReader(mem);
            if (reader.ReadString() != "A*")
            {
                throw new System.Exception("Invalid magic number in saved data");
            }
            meta.version = new Version(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
            meta.graphs  = reader.ReadInt32();
            meta.guids   = new string[reader.ReadInt32()];
            for (int i = 0; i < meta.guids.Length; i++)
            {
                meta.guids[i] = reader.ReadString();
            }
            meta.typeNames = new string[reader.ReadInt32()];
            for (int i = 0; i < meta.typeNames.Length; i++)
            {
                meta.typeNames[i] = reader.ReadString();
            }
            meta.nodeCounts = new int[reader.ReadInt32()];
            for (int i = 0; i < meta.nodeCounts.Length; i++)
            {
                meta.nodeCounts[i] = reader.ReadInt32();
            }
            return(meta);
#endif
        }
Ejemplo n.º 15
0
        public bool OpenDeserialize(byte[] bytes)
        {
#if !ASTAR_NO_JSON
            // Add some converters so that we can deserialize Unity builtin types
            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());
#endif

            // Copy the bytes to a stream
            zipStream = new MemoryStream();
            zipStream.Write(bytes, 0, bytes.Length);
            zipStream.Position = 0;
            try {
                zip = ZipFile.Read(zipStream);
            } catch (Exception e) {
                // Catches exceptions when an invalid zip file is found
                Debug.LogError("Caught exception when loading from zip\n" + e);

                zipStream.Dispose();
                return(false);
            }

            meta = DeserializeMeta(zip["meta" + jsonExt]);

            if (FullyDefinedVersion(meta.version) > FullyDefinedVersion(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 +
                                 "\nThis is usually fine as the stored data is usually backwards and forwards compatible." +
                                 "\nHowever node data (not settings) can get corrupted between versions (even though I try my best to keep compatibility), 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");
            }
            else if (FullyDefinedVersion(meta.version) < FullyDefinedVersion(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 (even though I try my best to keep compatibility), 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);
        }
Ejemplo n.º 16
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();
		}
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
 public bool OpenDeserialize(byte[] bytes)
 {
     this.str = new MemoryStream();
     this.str.Write(bytes, 0, bytes.Length);
     this.str.set_Position(0L);
     try
     {
         this.zip = ZipFile.Read(this.str);
     }
     catch (Exception ex)
     {
         Debug.LogWarning("Caught exception when loading from zip\n" + ex);
         this.str.Dispose();
         return(false);
     }
     this.meta = this.DeserializeMeta(this.zip["meta.binary"]);
     if (this.meta.version > AstarPath.Version)
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from a newer version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.meta.version
         }));
     }
     else if (this.meta.version < AstarPath.Version)
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from an older version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.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 recommendedto 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);
 }
Ejemplo n.º 19
0
        private GraphMeta DeserializeMeta(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new System.Exception("No metadata found in serialized data.");
            }

#if !ASTAR_NO_JSON
            string s = GetString(entry);

            JsonReader reader = new JsonReader(s, readerSettings);
            return((GraphMeta)reader.Deserialize(typeof(GraphMeta)));

            //JsonConvert.DeserializeObject<GraphMeta>(s,settings);
#else
            var meta = new GraphMeta();

            var mem = new System.IO.MemoryStream();
            entry.Extract(mem);
            mem.Position = 0;
            var reader = new System.IO.BinaryReader(mem);
            if (reader.ReadString() != "A*")
            {
                throw new System.Exception("Invalid magic number in saved data");
            }
            int major    = reader.ReadInt32();
            int minor    = reader.ReadInt32();
            int build    = reader.ReadInt32();
            int revision = reader.ReadInt32();

            // Required because when saving a version with a field not set, it will save it as -1
            // and then the Version constructor will throw an exception (which we do not want)
            if (major < 0)
            {
                meta.version = new Version(0, 0);
            }
            else if (minor < 0)
            {
                meta.version = new Version(major, 0);
            }
            else if (build < 0)
            {
                meta.version = new Version(major, minor);
            }
            else if (revision < 0)
            {
                meta.version = new Version(major, minor, build);
            }
            else
            {
                meta.version = new Version(major, minor, build, revision);
            }

            meta.graphs = reader.ReadInt32();
            meta.guids  = new string[reader.ReadInt32()];
            for (int i = 0; i < meta.guids.Length; i++)
            {
                meta.guids[i] = reader.ReadString();
            }
            meta.typeNames = new string[reader.ReadInt32()];
            for (int i = 0; i < meta.typeNames.Length; i++)
            {
                meta.typeNames[i] = reader.ReadString();
            }
            meta.nodeCounts = new int[reader.ReadInt32()];
            for (int i = 0; i < meta.nodeCounts.Length; i++)
            {
                meta.nodeCounts[i] = reader.ReadInt32();
            }
            return(meta);
#endif
        }
Ejemplo n.º 20
0
		private GraphMeta DeserializeMeta (ZipEntry entry) {
			if ( entry == null ) throw new System.Exception ("No metadata found in serialized data.");

#if !ASTAR_NO_JSON
			string s = GetString (entry);
			
			JsonReader reader = new JsonReader(s,readerSettings);
			return (GraphMeta)reader.Deserialize(typeof(GraphMeta));
			 //JsonConvert.DeserializeObject<GraphMeta>(s,settings);
#else
			var meta = new GraphMeta();

			var mem = new System.IO.MemoryStream();
			entry.Extract (mem);
			mem.Position = 0;
			var reader = new System.IO.BinaryReader(mem);
			if ( reader.ReadString() != "A*" ) throw new System.Exception ("Invalid magic number in saved data");
			meta.version = new Version (reader.ReadInt32 (),reader.ReadInt32 (),reader.ReadInt32 (),reader.ReadInt32 ());
			meta.graphs = reader.ReadInt32 ();
			meta.guids = new string[reader.ReadInt32()];
			for ( int i = 0; i < meta.guids.Length; i++ ) meta.guids[i] = reader.ReadString();
			meta.typeNames = new string[reader.ReadInt32()];
			for ( int i = 0; i < meta.typeNames.Length; i++ ) meta.typeNames[i] = reader.ReadString();
			meta.nodeCounts = new int[reader.ReadInt32()];
			for ( int i = 0; i < meta.nodeCounts.Length; i++ ) meta.nodeCounts[i] = reader.ReadInt32();
			return meta;
#endif
		}
Ejemplo n.º 21
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");
            }
            return true;
        }
Ejemplo n.º 22
0
		private GraphMeta DeserializeMeta (ZipEntry entry) {
			if ( entry == null ) throw new Exception ("No metadata found in serialized data.");

#if !ASTAR_NO_JSON
			string s = GetString (entry);
			
			var reader = new JsonReader(s,readerSettings);
			return (GraphMeta)reader.Deserialize(typeof(GraphMeta));
#else
			var meta = new GraphMeta();

			var mem = new System.IO.MemoryStream();
			entry.Extract (mem);
			mem.Position = 0;
			var reader = new System.IO.BinaryReader(mem);
			if ( reader.ReadString() != "A*" ) throw new System.Exception ("Invalid magic number in saved data");
			int major = reader.ReadInt32 ();
			int minor = reader.ReadInt32 ();
			int build = reader.ReadInt32 ();
			int revision = reader.ReadInt32 ();

			// Required because when saving a version with a field not set, it will save it as -1
			// and then the Version constructor will throw an exception (which we do not want)
			if ( major < 0 ) meta.version = new Version (0, 0);
			else if ( minor < 0 ) meta.version = new Version (major, 0);
			else if ( build < 0 ) meta.version = new Version (major, minor);
			else if ( revision < 0 ) meta.version = new Version (major, minor, build);
			else meta.version = new Version (major, minor, build, revision);

			meta.graphs = reader.ReadInt32 ();

			meta.guids = new string[reader.ReadInt32()];
			for ( int i = 0; i < meta.guids.Length; i++ ) meta.guids[i] = reader.ReadString();

			meta.typeNames = new string[reader.ReadInt32()];
			for ( int i = 0; i < meta.typeNames.Length; i++ ) meta.typeNames[i] = reader.ReadString();

			meta.nodeCounts = new int[reader.ReadInt32()];
			for ( int i = 0; i < meta.nodeCounts.Length; i++ ) meta.nodeCounts[i] = reader.ReadInt32();

			return meta;
#endif
		}
Ejemplo n.º 23
0
		public bool OpenDeserialize (byte[] bytes) {
#if !ASTAR_NO_JSON
			// Add some converters so that we can deserialize Unity builtin types
			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());
#endif

			str = new MemoryStream();
			str.Write(bytes,0,bytes.Length);
			str.Position = 0;
			try {
				zip = ZipFile.Read(str);
			} catch (Exception e) {
				//Catches exceptions when an invalid zip file is found
				Debug.LogWarning ("Caught exception when loading from zip\n"+e);

				str.Dispose ();
				return false;
			}
			meta = DeserializeMeta (zip["meta"+jsonExt]);
			
			if (FullyDefinedVersion(meta.version) > FullyDefinedVersion(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 +
				                  "\nThis is usually fine as the stored data is usually backwards and forwards compatible." +
				                  "\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");
			} else if (FullyDefinedVersion(meta.version) < FullyDefinedVersion(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;
		}
Ejemplo n.º 24
0
		public void OpenSerialize () {
			// Create a new zip file, here we will store all the data
			zip = new ZipFile();
			zip.AlternateEncoding = System.Text.Encoding.UTF8;
			zip.AlternateEncodingUsage = ZipOption.Always;

#if !ASTAR_NO_JSON
			// Add some converters so that we can serialize some Unity types
			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.PrettyPrint = settings.prettyPrint;
#endif			
			meta = new GraphMeta();
		}