Draging a mesh with "Gizmos-context"


is there any way to draw a custom mesh (in our case: custom generated) in the context of OnDrawGizmos? More specifically, I really like the feature that you can click on any gizmo drawn using Gizmos.Draw* and it auto-selects the object in which the gizmo has been drawn.

// Works with clicking on the cube, but does not draw a mesh and there is no Gizmos.DrawMesh()
Gizmos.DrawCube(center, outerBounds);

// Draws a custom mesh, but clicking on the area won't auto-select the object where this call is in.

Just a note how the problem can be “somewhat circumvented”:

Graphics.DrawMesh(mesh, ...);
var c = Gizmos.color;
Gizmos.color = new Color(0,0,0,0); // invisible
Gizmos.DrawCube(center, mesh.bounds.size);
Gizmos.color = c;

This will first draw the mesh and then an invisible bounding box gizmo. Picking is not perfect but for some (=our) cases its “good enough”.

PS: I’ll still leave the question open in the hope that someone figure out how to use UnityEditor.HandleUtility.AddControl to redirect editor picking to an existing object. I couldn’t. :wink: