How can I make a clickable grid in the sceneview?

I’ve seen a few threads which are similar to this, but nothing is quite what I need. What I’m trying to make is a Handle/Gizmo-based editor in the sceneview, where you can click on the Tiles of a grid of squares, and in that way put down floor tiles or do other things.

I’ve made a grid and am iterating through it with two simple ‘for’ loops (for x and y coordinates). I’m drawing the grid with DrawSolidRectangleWithOutline as this seemed to be the only way to make a 2D grid in 3D space.

When I click or hover on the grid somewhere I want to send the x and y coordinates of the Tile to go into a function. This would for example change the color of the tile so it can be seen it is hovered, or spawn a floor tile at that position.

With raycasting (using GUIPointToWorldRay) I have to add a colider, resize according to the gridsize and then get hit.point. This sort of works but now I have an extra component to deal with etc.

Is there a better way to do this? I’m not so familiar with Handles and Gizmos but possibly there is something here which I have simply not found. Any references or tutorials would be appreciated.

Since you’ve asked - yes there is. But it’s a little hardcore - you could actual movement-handles (can be of any shape) each of which overlays on top of your grid pieces.

If you manage to project square corners of your grid piece onto screen, you can make the 2D-handles have the shape of the projected-square (could look like trapezoid as a result, etc)

You can detect if you are inside of the shape or not, and do something to the corresponding grid-tile (move it using delta etc)

No component mess, but watch out for performance - this is heavily related to GUI and can bite hard