Pathfinding.LayerGridGraph.GetNearest C# (CSharp) Method

GetNearest() public method

public GetNearest ( Vector3 position, NNConstraint constraint, GraphNode hint = null ) : NNInfo
position UnityEngine.Vector3
constraint NNConstraint
hint GraphNode
return NNInfo
		public override NNInfo GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint = null) {
			
			if (nodes == null || depth*width*layerCount != nodes.Length) {
				//Debug.LogError ("NavGraph hasn't been generated yet");
				return new NNInfo ();
			}
			
			position = inverseMatrix.MultiplyPoint3x4 (position);
			
			int x = Mathf.Clamp (Mathf.RoundToInt (position.x-0.5F)  , 0, width-1);
			int z = Mathf.Clamp (Mathf.RoundToInt (position.z-0.5F)  , 0, depth-1);
			
			int index = width*z+x;
			float minDist = float.PositiveInfinity;
			LevelGridNode minNode = null;
			for (int i=0;i<layerCount;i++) {
				LevelGridNode node = nodes[index + width*depth*i];
				if (node != null) {
					float dist =  ((Vector3)node.position - position).sqrMagnitude;
					if (dist < minDist) {
						minDist = dist;
						minNode = node;
					}
				}
			}
			
			return new NNInfo(minNode);
			
		}