Search Unity

Asset selector window

Discussion in 'Scripting' started by sberlemont, Jan 9, 2011.

  1. sberlemont

    sberlemont

    Joined:
    May 16, 2010
    Posts:
    37
    Hi,

    How to call the Asset selector window (see screenshots) from an editor script?

    This window shows up for example when clicking on "select" in a material component.

    Thanks.
     

    Attached Files:

  2. disband85

    disband85

    Joined:
    Dec 7, 2010
    Posts:
    83
    Your question seems a bit vague. Can you provide a code example of what you're trying to do? If you're just trying to assign a different texture to a material in code, there's no need to open the asset selector window. You would just use GetComponent<Material>() to get the material and call SetTexture().
     
  3. sberlemont

    sberlemont

    Joined:
    May 16, 2010
    Posts:
    37
    I would like to select an asset (model) which is in the project view from a GUI. I wonder if there is a function similar to EditorUtility.OpenFilePanel() that displays the asset of a particular type (Texture, Model, etc.).

    For example, when you click on "select" (see screenshot above) on a texture, a selection window appears. I wonder how to call this window from a script.
     
  4. sberlemont

    sberlemont

    Joined:
    May 16, 2010
    Posts:
    37
    any idea?
     
  5. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Check the docs for EditorGUI and EditorGUILayout. I haven't done much editor scripting recently, but there should be a control there that will allow you to select an asset of a specified type.
     
  6. GlitchEnzo

    GlitchEnzo

    Joined:
    Aug 31, 2011
    Posts:
    1
    I was just looking for the exact same thing, and I prefer it when the actual answer is given in the forum thread, so here it is:

    You specificially want the ObjectField method. To use it with a Texture, you would do the following

    Code (csharp):
    1. myTexture = (Texture2D)EditorGUILayout.ObjectField("My Texture", myTexture, typeof(Texture2D), false);
     
    cinbot123 and quyrean like this.