Example #1
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);
            }
            return true;
        }
Example #2
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;
		}