Ejemplo n.º 1
0
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonDataReader(JsonReaderSettings settings)
		{
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}
			this.Settings = settings;
		}
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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.º 4
0
		/// <summary>
		/// Builds a common settings objects
		/// </summary>
		/// <param name="allowNullValueTypes"></param>
		/// <returns></returns>
		public static JsonReaderSettings CreateSettings(bool allowNullValueTypes)
		{
			JsonReaderSettings settings = new JsonReaderSettings();

			settings.AllowNullValueTypes = allowNullValueTypes;

			return settings;
		}
Ejemplo n.º 5
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">StringBuilder containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(StringBuilder input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input.ToString();
     this.SourceLength = this.Source.Length;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">string containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(string input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input;
     this.SourceLength = this.Source.Length;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="input">TextReader containing source</param>
 /// <param name="settings">JsonReaderSettings</param>
 public JsonReader(TextReader input, JsonReaderSettings settings)
 {
     this.Settings     = settings;
     this.Source       = input.ReadToEnd();
     this.SourceLength = this.Source.Length;
 }