Search Unity

Trying to create a UI Image preview in Editor GUI

Discussion in 'Immediate Mode GUI (IMGUI)' started by will_ai, Jul 13, 2017.

  1. will_ai

    will_ai

    Joined:
    Mar 13, 2017
    Posts:
    3
    Hi everyone, trying to add a preview image in my Editor gui extension. Now I've not done much Editor GUI before but I've given it a go but not really getting anywhere.

    I've created a slot for adding a UI Image but I would like to show a preview window of the image as a preview of the image would be extremely helpful.

    I've looked at the docs here: https://docs.unity3d.com/ScriptReference/EditorGUI.DrawPreviewTexture.html

    But I'm getting the following error: Expression denotes a `type', where a `variable', `value' or `method group' was expected

    Here is my Code:

    Code (CSharp):
    1.  
    2. inventoryItemList.itemList[viewIndex-1].cardIcon = EditorGUILayout.ObjectField ("Card Icon", inventoryItemList.itemList[viewIndex-1].cardIcon, typeof (Image), false) as Image;
    3.  
    4.  
    5.                 //Preview Image
    6.                 Texture texture = inventoryItemList.itemList[viewIndex-1].cardIcon.mainTexture;
    7.  
    8.                 EditorGUI.DrawPreviewTexture(Rect(25,60,100,100), texture);
    9.  
    If anyone can help point me in the right direction that would be really great.

    Thanks!
     
    Last edited: Jul 13, 2017
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    instead of Rect you should write new Rect