context: //#define SingleCoreOptimize
  using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  //using Pathfinding;
  using Pathfinding.Util;
  
  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 AstarPath active {
  			get {
  				return AstarPath.active;
  			}
  		}
  		
  #region Fields
  		[System.NonSerialized]
  		public NavMeshGraph navmesh; 	/**< Shortcut to the first NavMeshGraph. Updated at scanning time. This is the only reference to NavMeshGraph in the core pathfinding scripts */
  		
  		[System.NonSerialized]
  		public GridGraph gridGraph;		/**< Shortcut to the first GridGraph. Updated at scanning time. This is the only reference to GridGraph in the core pathfinding scripts */
  		
  		[System.NonSerialized]
  		public PointGraph pointGraph;		/**< Shortcut to the first PointGraph. Updated at scanning time. This is the only reference to PointGraph in the core pathfinding scripts */
  		
  		[System.NonSerialized]
  		/** Holds temporary path data for pathfinders.
  		 * One array for every thread.
  		 * Every array is itself an array with a number of NodeRun object of which there is one per node of.
  		 * These objects holds the temporary path data, such as the G and H scores and the parent node.
  		 * This is separate from the static path data, e.g connections between nodes.
  		 * \see CreateNodeRuns
  		 */
  		public NodeRun[][] nodeRuns;
  		
  		/** All supported graph types. Populated through reflection search */
  		public System.Type[] graphTypes = null;
  		
  		[System.NonSerialized]
  		/** All graphs this instance holds. This will be filled only after deserialization has completed */
  		public NavGraph[] graphs = new NavGraph[0];
  		
  		/** Links placed by the user in the scene view. */
  		[System.NonSerialized]
  		public UserConnection[] userConnections = new UserConnection[0];
  		
  		//Serialization Settings
  		
  		/** Has the data been reverted by an undo operation.
  		 * Used by the editor's undo logic to check if the AstarData has been reverted by an undo operation and should be deserialized */
  		public bool hasBeenReverted = false;
  		
  		[SerializeField]
  		private byte[] data;
  		
  		public uint dataChecksum;
  		
  		public byte[] data_backup;
  		
  		public byte[] data_cachedStartup;
  		
  		public byte[] revertData;
  		
  		/** 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.
  		 */
  		public bool cacheStartup = false;
  		
  		public bool compress = false;
  		
  		//End Serialization Settings
  		
  #endregion
  		
  		public byte[] GetData () {
  			return data;
  		}
  		
  		public void SetData (byte[] data, uint checksum) {
  			this.data = data;
  			dataChecksum = checksum;
  		}
  		
  		/** Loads the graphs from memory, will load cached graphs if any exists */
  		public void Awake () {
  			
  			/* Set up default values, to not throw null reference errors */
  			userConnections = new UserConnection[0];
  			
  #if false
  			graphs = new NavGraph[1] { CreateGraph (typeof(LinkGraph)) };
  #else
  			graphs = new NavGraph[0];
  #endif
  			/* End default values */
  			
  			if (cacheStartup && data_cachedStartup != null) {
  				LoadFromCache ();
  			} else {
  				DeserializeGraphs ();
  			}
  			
  
  			/*Pathfinding.Serialize.AstarSerializer sr = new Pathfinding.Serialize.AstarSerializer(this);
  			byte[] dt = sr.Serialize ();
  			
  			sr.Deserialize(dt);
  			 */
  		}
  		
  		[System.Obsolete]
  		public void CollectNodes (int numTemporary) {
  			/*int nodeCount = 0;
  			for (int i=0;i<graphs.Length;i++) {
  				if (graphs[i].nodes != null)
  					nodeCount += graphs[i].nodes.Length;
  			}
  			
  			nodes = new Node[nodeCount + numTemporary];
  			int counter = 0;
  			for (int i=0;i<graphs.Length;i++) {
  				if (graphs[i].nodes != null) {
  					Node[] gNodes = graphs[i].nodes;
  					for (int j=0;j<gNodes.Length;j++, counter++) {
  						nodes[counter] = gNodes[j];
  						gNodes[j].nodeIndex = counter;
  					}
  				}
  			}*/
  		}
  		
  		public void AssignNodeIndices () {
  			int counter = 0;
  			for (int i=0;i<graphs.Length;i++) {
  				if (graphs[i].nodes == null) continue;
  				Node[] nodes = graphs[i].nodes;
  				for (int j=0;j<nodes.Length;j++, counter++) {
  					if (nodes[j] != null)
  						nodes[j].SetNodeIndex(counter);
  				}
  			}
  		}
  		
  		/** Creates the structure for holding temporary path data.
  		 * The data is for example the G, H and F scores and the search tree.
  		 * The number of nodeRuns must be no less than the number of nodes contained in all graphs.
  		 * So after adding nodes, this MUST be called.\n
  		 * Ideally, I would code an update function which reuses most of the previous ones instead of recreating it every time.
  		 * \param numParallel Number of parallel threads which will use the data.
  		 * \see #nodeRuns
  		 * \see AstarPath::UpdatePathThreadInfoNodes
  		 */
  		public void CreateNodeRuns (int numParallel) {
  			
  			if (graphs == null) throw new System.Exception ("Cannot create NodeRuns when no graphs exist. (Scan and or Load graphs first)");
  			
  			int nodeCount = 0;
  			for (int i=0;i<graphs.Length;i++) {
  				if (graphs[i].nodes != null)
  					nodeCount += graphs[i].nodes.Length;
  			}
  			
  			AssignNodeIndices ();
  			
  #if !SingleCoreOptimize
  			nodeRuns = new NodeRun[numParallel][];
  			for (int i=0;i<nodeRuns.Length;i++) {
  				nodeRuns[i] = new NodeRun[nodeCount];
  				
  				int counter = 0;
  				for (int j=0;j<graphs.Length;j++) {
  					Node[] nodes = graphs[j].nodes;
  					if (nodes == null) continue;
  					for (int q=0;q<nodes.Length;q++, counter++) {
  						if (nodes[q] != null) {
  							nodeRuns[i][counter] = new NodeRun ();
  							nodeRuns[i][counter].Link (nodes[q],counter);
  						}
  					}
  				}
  			}
  #endif
  			active.UpdatePathThreadInfoNodes ();
  		}
  		
  		/** 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. It is the only reference to specific graph types in the pathfinding core.\n
  		 */
  		public void UpdateShortcuts () {
  
gt: 			navmesh = (NavMeshGraph)FindGraphOfType (typeof(NavMeshGraph));