public Vector2 ActualClosestPointTo <T>(Vector2 pos) where T : Object
        {
            QuadTree.PositionObjectPair opp =
                ObjectsWithinNode.OrderBy(a => Vector2.Distance(pos, a.Position)).Where(a => a.Obj is T).FirstOrDefault();

            return(opp == null ? Vector2.zero : opp.Position);
        }
        private QuadTree.PositionObjectPair ObjectClosestToRecursive <T>(Vector2 pos) where T : Object
        {
            if (ObjectsWithinNode.Length == 0 || ObjectsWithinNode.Any(a => a.Obj is T) == false)
            {
                return(null);
            }

            QuadTree.PositionObjectPair found = null;

            if (NodeBounds.Contains(pos))
            {
                foreach (QuadTreeNode child in ChildNodes)
                {
                    found = child.ObjectClosestToRecursive <T>(pos);
                    if (found != null)
                    {
                        break;
                    }
                }

                if (found == null)
                {
                    foreach (var t in
                             ObjectsWithinNode.OrderBy(a => Vector2.Distance(a.Position, pos)))
                    {
                        if (t.Obj is T)
                        {
                            if (ObstructionLayer == "" || Physics2D.Raycast(pos, ((Vector2)t.Position - pos).normalized, Vector2.Distance(pos, t.Position), 1 << LayerMask.NameToLayer(ObstructionLayer)) == false)
                            {
                                found = t;
                                break;
                            }
                        }
                    }
                }
            }

            return(found);
        }
 public Vector2 ClosestPointTo(Vector2 pos)
 {
     QuadTree.PositionObjectPair foundPos = ObjectClosestToRecursive <Object>(pos);
     return(foundPos != null ? foundPos.Position : pos);
 }
 public Object ClosestObjectTo(Vector2 pos)
 {
     QuadTree.PositionObjectPair foundPos = ObjectClosestToRecursive <Object>(pos);
     return(foundPos != null ? foundPos.Obj : null);
 }
 public T ClosestObjectTo <T>(Vector2 pos) where T : Object
 {
     QuadTree.PositionObjectPair foundPos = ObjectClosestToRecursive <T>(pos);
     return(foundPos != null ? (T)foundPos.Obj : null);
 }