Detect Mouse Click Over BoxCollider2D in Scene View (Custom Editor)

Hey guys I’ve seen a bunch of similar topics to mine but none seem to solve my issue. I’ve got a bunch of BoxCollider2D objects (I’m creating a tile-based game) in my scene and am trying to use a custom editor script to detect mouse clicks on them. Here’s what I have:

private void OnSceneGUI()
{
    Event e = Event.current;

    if (e != null && e.type == EventType.MouseDown && e.button == 0)
    {
            Debug.Log("Mouse down!");

            Ray r = Camera.current.ScreenPointToRay(e.mousePosition);

            RaycastHit2D hitInfo = Physics2D.GetRayIntersection(r, 10f, 1 << LayerMask.NameToLayer("Tile"));
            if (hitInfo.collider != null)
            {
                    Tile t = hitInfo.collider.GetComponent<Tile>();
                    if (t != null)
                    {
                        // Do stuff...

                        e.Use();
                    }
                }
            }
        }

Problem is that it’s detecting mouse clicks on tiles NOWHERE NEAR the mouse. Any idea what I’m doing wrong? I’m sure it’s something super obvious but I’ve been here for 2 nights now and still can’t see it.

As expected, as soon as I post something I figure it out. Posting here in case anyone else is having the same issue.

Ray should have been calculated like so:

Ray r = HandleUtility.GUIPointToWorldRay(e.mousePosition);