Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

How to add component to the SceneView Gizmos dropdown without using OnDrawGizmos function

Discussion in 'Extensions & OnGUI' started by Xarbrough, Oct 12, 2018.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    311
    When I add OnDrawGizmos to my MonoBehaviour, the component is automatically added to the Gizmos dropdown list in the SceneView:

    GizmoWindow.png

    However, I prefer separating my editor from runtime code, which is why I like to use the DrawGizmo attribute. With the attribute, I decorate a static function within my editor class and can draw the same Gizmo as before.

    Sadly, I have noticed, that now my component does not appear in the list anymore. Hence, I cannot toggle the Gizmo via the list or by expanding/collapsing the component in the inspector.

    Is there a way for me to register my custom Gizmo function with the dropdown list?

    A partial solution, to at least toggle gizmos from the inspector, is to use:

    UnityEditorInternal.InternalEditorUtility.GetIsInspectorExpanded(component);


    With the internal utility I can check if the component is expanded and then decide whether to draw or now. However, I would still like it to also appear in the SceneView Gizmos list.
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    521
    Doesn't look like it. A quick read of the source says that they gather all the valid classes through an 'AnnotationUtility' class. It seems like DrawGizmo isn't included in the gathering.

    (DrawGizmo also doesn't capture mouse events, unfortunately.)