How To Display Camera In Custom Editor Window?

Hey Again everyone I am trying to create a tile builder interface and would like to have my window display the what the main camera is showing. Here’s the Code I am using currently, but all I get is a tiny Box with no image.

Thanks

private GameObject camObj;
	private Camera cam;

	void OnEnable(){
		if (!camObj) {
			SetCamera ();
		}
	}

	void OnGUI(){
		if (!camObj) {
			SetCamera ();
			Repaint ();
		}
		else {
			RenderTexture tex = cam.targetTexture;
			Texture img = tex as Texture;
			GUILayout.BeginArea (new Rect(0,0, Screen.width,Screen.height));
			GUILayout.Box (img);
			GUILayout.EndArea ();
		}
	}
	void SetCamera(){
		camObj = GameObject.Find ("Main Camera");
		if(camObj) cam = camObj.GetComponent<Camera>();
	}

Have you tried

?

Or have you tried just using the default viewports and building your controls into them?

1 Like

I haven’t tried default viewports, but Handles.DrawCamera seems to work okay! thank you very much.