Custom Editor Object Selection

Hi, was wondering if it’s possible to customize the selection area for an object?

I have an empty game object which has a custom class. This custom class draws a polygon in the scene view. How can I let the user click on the polygon in order to select the game object?

Mesh can do this, but I can’t figure out how. Seems Gizmos can only draw cube’s, line’s and sphere’s.

It is possible, but I never really found this straight forward to do.

Basically, the way I did it is:

  • Register an EditorApplication.onSceneGUI. Maybe you can use “OnDrawGizmo” as well - (I haven’t checked on this)
  • during Event.current.type == Layout call HandleUtility.AddControl to register your “distance to the mouse”. You can use all the Distance* functions in HandleUtility to help calculating the correct distance. (Its probably easier to allocate an own control ID for your object)
  • In Event.current.type == MouseDown and if the HandleUtility.nearestControl is your previously registered control ID, set the selected object using Selection.activeObject.

I hope this helps. Maybe I can write some tutorial code someday… when I got time again… ^^

Thanks, I’ll check that out