How to draw a textured plane in Editor?

I want to make a custom editor which draws a textured plane in 3-space (not like a billboard icon). Think of it as a reference object. Is this possible, and which API’s would be involved?

You can use the usual procedure. Just use GameObjects and a camera. Make sure you use a seperate unused layer so it’s seperated from the actual scene.

The next important thing is that you set the hideFlags of all objects you create for your editor to at least “DontSave” or “HideAndDontSave”, otherwise the object get saved into the current scene.

If you want to use an EditorWindow, you can use Camera.Render in OnGUI() to render the camera into the editor window. Note: make sure you only call it in the repaint step.

This is what’s working for me. Props to Bunny83 and syclamoth!

@script ExecuteInEditMode()
var aMesh : Mesh;
var mat : Material;

function Start () {
	hideFlags = HideFlags.HideAndDontSave;
}

function OnDrawGizmos() {
    // SetPass to 0 if the material doesnt have a texture.
    mat.SetPass(1);
    Graphics.DrawMeshNow(aMesh, Matrix4x4.Scale(transform.localScale));
}