Open ObjectSelector window from Editor Script

I’m trying to replicate the Material ObjectField seen in the Inspector, except that I also want to view the material modifications to the texture. I’ve got everything working except for the Select button, which needs to open an Object Picker window. I cannot figure out how to open this window without using the default ObjectField class, which I can’t use because it doesn’t offer an equivalent to EditorGUI.DrawPreviewTexture().

What I’ve tried (unsuccessfully) thus far:

  • Resizing the ObjectField to fit in
    that small “Select” rectangle

  • Manually opening the ObejectPicker

    EditorWindow.GetWindow(typeof(ObjectSelector), true, “Object Picker”, true);

I guess ObjectSelector is hiding somewhere, because I can’t seem to figure out what it inherits from.

Unity 4.2 exposes this in the Editor API:

Editor: Added EditorGUIUtility.ShowObjectPicker to let editor extensions use it on demand.

Bit of a necropost, but I was looking to do this too. I had a look around the assembly using ILSpy, and ObjectSelector is an internal class, and you can use it with reflection to call all the methods you need, but it’s very unwieldy. I’d just recommend using FindObjectsOfType and sticking the results in a window.