Search Unity

Draggable preview in inspector (like the one for FBX)

Discussion in 'Immediate Mode GUI (IMGUI)' started by alejobrainz, Jun 21, 2015.

  1. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Hello. I'm trying to display a preview within the inspector. So far, I've been able to display it inline using the CreateEditor and OnPreview methods:

    Screen Shot 2015-06-21 at 8.35.56 AM.png

    Now I'd like to make ti a draggable panel like the FBX inspector:
    Screen Shot 2015-06-21 at 8.32.25 AM.png

    But have no idea on how to achieve this. Any clues?

    Thanks!!
     
  2. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    Code (csharp):
    1.  
    2.  
    3. GameObject lhs;
    4. Editor lhsEditor;
    5. GUIStyle previewBackground;
    6. // Set the previewBackground.normal.background texture to a texture with whatever the background is.
    7. // I usually just create a small 1x1 px texture2d with the color
    8. // Color(.15625f, .15625f, .15625f, 1f), which is pretty close to the default gray
    9.  
    10. /// ....
    11.  
    12. if (lhs != null)
    13. {
    14.     if(lhsEditor == null)
    15.         lhsEditor = Editor.CreateEditor(lhs);
    16.     lhsEditor.OnPreviewGUI(lhsPreviewRect, previewBackground);
    17. }
    18.  
     
  3. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Thanks for the replay Karl. I Did manage to get the editor to show on the inspector. What I'm trying to figure out is how to make the bar that allows one to drag vertically and grow/shrink the preview on top of the inspector values:

    Screen Shot 2015-06-23 at 7.36.36 PM.png

    Any ideas are welcome!
     
  4. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    Oh, when you said "draggable panel" I assumed you meant the preview well was draggable. Apologies for the off-topic reply.
     
  5. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
  6. startassets

    startassets

    Joined:
    Feb 13, 2017
    Posts:
    11