NodeManager.GetNodeFromLocation C# (CSharp) Method

GetNodeFromLocation() public method

Gets the tile from location.
public GetNodeFromLocation ( Vector3 location ) : Node
location Vector3
return Node
    public Node GetNodeFromLocation(Vector3 location)
    {
        int xIndex = (int)Mathf.Floor ((location.x - left.x) / (objectManager.MapData.NodeSize.x));
        int zIndex = size_y + ((int)Mathf.Floor ((location.z - left.y) / objectManager.MapData.NodeSize.y));

        if(objectManager.MapData.IsIsoGrid)
        {
            xIndex = (int)Mathf.Round((2f*location.x + objectManager.MapData.NodeSize.x - 2f * left.x) / objectManager.MapData.NodeSize.x) - 2;
            zIndex = (int)Mathf.Round((location.z - (objectManager.MapData.NodeSize.y / 2f) - right.y - ((xIndex%2==1)?objectManager.MapData.NodeSize.y/2f:0f)) / objectManager.MapData.NodeSize.y);
        }

        // out of bounds check
        if (zIndex >= size_y || zIndex < 0 || xIndex >= size_x || xIndex < 0)
            return null;

        return nodes [xIndex, zIndex];
    }