Search Unity

Display a preview image in the GUI editor

Discussion in 'Editor & General Support' started by knobby67, Feb 21, 2017.

  1. knobby67

    knobby67

    Joined:
    Aug 30, 2015
    Posts:
    389
    Hi All,
    I'm learning Unity and am trying to display an image in a editor gui window. Basically I'd like to say load "home/image/image.png", resize image, then display in a editor window at position.
    I've tried everything I can find, cut and pasted tutorials but nothing seems to work. But the best I can get is a window that when click opens a file browser.
    Can someone point me to a way to do this please?

    The last way I tried to do it was
    Code (csharp):
    1.  
    2.             Texture2D image = null;
    3.  
    4.             image = EditorGUI.ObjectField(Rect(3,3,200,20), "/home/tony/Dropbox/Unity3d/Projects/Assets/Games/demo1/Texture/f1.png",image, Texture);
    5.  
    6.             EditorGUI.DrawPreviewTexture( Rect(25,60,100,100), image);
    7.  
    but this gives loads of errors, all along the lines of "type', where a `variable', `value' or `method group' was expected"

    eg

    from line 4 and 6 above
    Assets/Editor/Designer_Menu.cs(124,34): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
     
    Last edited: Feb 21, 2017