Search Unity

Custom Editor Object Selection

Discussion in 'Immediate Mode GUI (IMGUI)' started by CDF, Jan 15, 2015.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    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.
     
  2. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    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... ^^
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Thanks, I'll check that out