Asset selector window

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.

469612--16474--$Screen shot 2011-01-09 at 5.13.52 PM.png
469612--16475--$Screen shot 2011-01-09 at 5.13.37 PM.png

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() to get the material and call SetTexture().

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.

any idea?

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.

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

myTexture = (Texture2D)EditorGUILayout.ObjectField("My Texture", myTexture, typeof(Texture2D), false);
2 Likes