context: using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  using System.Reflection;
  #if UNITY_WINRT && !UNITY_EDITOR
  //using MarkerMetro.Unity.WinLegacy.IO;
  //using MarkerMetro.Unity.WinLegacy.Reflection;
  #endif
  
  namespace Pathfinding {
  	[System.Serializable]
  	/** Stores the navigation graphs for the A* Pathfinding System.
  	 * \ingroup relevant
  	 *
  	 * An instance of this class is assigned to AstarPath.astarData, from it you can access all graphs loaded through the #graphs variable.\n
  	 * This class also handles a lot of the high level serialization.
  	 */
  	public class AstarData {
  		/** Shortcut to AstarPath.active */
  		public static AstarPath active {
  			get {
  				return AstarPath.active;
  			}
  		}
  
  		#region Fields
  		/** Shortcut to the first NavMeshGraph.
  		 * Updated at scanning time
  		 */
  		public NavMeshGraph navmesh { get; private set; }
  
  		/** Shortcut to the first GridGraph.
  		 * Updated at scanning time
  		 */
  		public GridGraph gridGraph { get; private set; }
  
  
  		/** Shortcut to the first PointGraph.
  		 * Updated at scanning time
  		 */
  		public PointGraph pointGraph { get; private set; }
  
  
  		/** All supported graph types.
  		 * Populated through reflection search
  		 */
  		public System.Type[] graphTypes { get; private set; }
  
  #if ASTAR_FAST_NO_EXCEPTIONS || UNITY_WINRT || UNITY_WEBGL
  		/** Graph types to use when building with Fast But No Exceptions for iPhone.
  		 * If you add any custom graph types, you need to add them to this hard-coded list.
  		 */
  		public static readonly System.Type[] DefaultGraphTypes = new System.Type[] {
  			typeof(GridGraph),
  			typeof(PointGraph),
  			typeof(NavMeshGraph),
  		};
  #endif
  
  		/** All graphs this instance holds.
  		 * This will be filled only after deserialization has completed.
  		 * May contain null entries if graph have been removed.
  		 */
  		[System.NonSerialized]
  		public NavGraph[] graphs = new NavGraph[0];
  
  		//Serialization Settings
  
  		/** Serialized data for all graphs and settings.
  		 * Stored as a base64 encoded string because otherwise Unity's Undo system would sometimes corrupt the byte data (because it only stores deltas).
  		 *
  		 * This can be accessed as a byte array from the #data property.
  		 *
  		 * \since 3.6.1
  		 */
  		[SerializeField]
  		string dataString;
  
  		/** Data from versions from before 3.6.1.
  		 * Used for handling upgrades
  		 * \since 3.6.1
  		 */
  		[SerializeField]
  		[UnityEngine.Serialization.FormerlySerializedAs("data")]
  		private byte[] upgradeData;
  
  		/** Serialized data for all graphs and settings */
  		private byte[] data {
  			get {
  				// Handle upgrading from earlier versions than 3.6.1
  				if (upgradeData != null && upgradeData.Length > 0) {
  					data = upgradeData;
  					upgradeData = null;
  				}
  				return dataString != null ? System.Convert.FromBase64String(dataString) : null;
  			}
  			set {
  				dataString = value != null ? System.Convert.ToBase64String(value) : null;
  			}
  		}
  
  		/** Backup data if deserialization failed.
  		 */
  		public byte[] data_backup;
  
  		/** Serialized data for cached startup.
  		 * If set, on start the graphs will be deserialized from this file.
  		 */
  		public TextAsset file_cachedStartup;
  
  		/** Serialized data for cached startup.
  		 *
  		 * \deprecated Deprecated since 3.6, AstarData.file_cachedStartup is now used instead
  		 */
  		public byte[] data_cachedStartup;
  
  		/** Should graph-data be cached.
  		 * Caching the startup means saving the whole graphs, not only the settings to an internal array (#data_cachedStartup) which can
  		 * be loaded faster than scanning all graphs at startup. This is setup from the editor.
  		 */
  		[SerializeField]
  		public bool cacheStartup;
  
  		//End Serialization Settings
  
  		#endregion
  
  		public byte[] GetData () {
  			return data;
  		}
  
  		public void SetData (byte[] data) {
  			this.data = data;
  		}
  
  		/** Loads the graphs from memory, will load cached graphs if any exists */
  		public void Awake () {
  			graphs = new NavGraph[0];
  			/* End default values */
  
  			if (cacheStartup && file_cachedStartup != null) {
  				LoadFromCache();
  			} else {
  				DeserializeGraphs();
  			}
  		}
  
  		/** Updates shortcuts to the first graph of different types.
  		 * Hard coding references to some graph types is not really a good thing imo. I want to keep it dynamic and flexible.
  		 * But these references ease the use of the system, so I decided to keep them.\n
  		 */
  		public void UpdateShortcuts () {
  			navmesh = (NavMeshGraph)FindGraphOfType(typeof(NavMeshGraph));
  
  			gridGraph = (GridGraph)FindGraphOfType(typeof(GridGraph));
  
  			pointGraph = (PointGraph)FindGraphOfType(typeof(PointGraph));
  		}
  
  		/** Load from data from #file_cachedStartup */
  		public void LoadFromCache () {
  			AstarPath.active.BlockUntilPathQueueBlocked();
  			if (file_cachedStartup != null) {
  				var bytes = file_cachedStartup.bytes;
  				DeserializeGraphs(bytes);
  
  				GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad);
  			} else {
  				Debug.LogError("Can't load from cache since the cache is empty");
  			}
  		}
  
  		#region Serialization
  
  		/** Serializes all graphs settings to a byte array.
  		 * \see DeserializeGraphs(byte[])
  		 */
  		public byte[] SerializeGraphs () {
  			return SerializeGraphs(Pathfinding.Serialization.SerializeSettings.Settings);
  		}
  
  		/** Serializes all graphs settings and optionally node data to a byte array.
  		 * \see DeserializeGraphs(byte[])
  		 * \see Pathfinding.Serialization.SerializeSettings
  		 */
  		public byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings) {
  			uint checksum;
  
  			return SerializeGraphs(settings, out checksum);
  		}
  
  		/** Main serializer function.
  		 * Serializes all graphs to a byte array
  		 * A similar function exists in the AstarPathEditor.cs script to save additional info */
  		public byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum) {
  			AstarPath.active.BlockUntilPathQueueBlocked();
  
  			var sr = new Pathfinding.Serialization.AstarSerializer(this, settings);
  			sr.OpenSerialize();
  			SerializeGraphsPart(sr);
  			byte[] bytes = sr.CloseSerialize();
  			checksum = sr.GetChecksum();
  			return bytes;
  		}
  
  		/** Serializes common info to the serializer.
  		 * Common info is what is shared between the editor serialization and the runtime serializer.
  		 * This is mostly everything except the graph inspectors which serialize some extra data in the editor
  		 */
  		public void SerializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr) {
  			sr.SerializeGraphs(graphs);
  			sr.SerializeExtraInfo();
  		}
  
  		/** Deserializes graphs from #data */
  		public void DeserializeGraphs () {
  
gt: 			if (data != null) {