- Home /
 
Custom scene view in editor window
I need to draw scene from the camera I want in an editor window. I found this reference. But it does not work. I need the exact functionality as in the link. Anyone got any leads?
Also I want to get mouse events in the window. Any help is appreciated.
Answer by Bunny83 · Feb 14, 2015 at 06:12 AM
You don't need RenderTextures (which are a pro feature) to render a camera to an editor window. Take a look at this:
 public Camera m_Cam;
 private Rect sceneRect;
 
 void OnGUI()
 {
     //...
     // get a rectangle somehow
     GUILayout.Box("");
     Rect R = GUILayoutUtility.GetLastRect();
 
     // important: only render during the repaint event
     if (Event.current.type == EventType.Repaint)
     {
         sceneRect = GUILayoutUtility.GetLastRect();
         sceneRect.y += 20; // adjust the windows header
 
         m_Cam.pixelRect = sceneRect;
         m_Cam.Render(); // render the camera into the window
     }
 
     /*
     Handles.SetCamera(m_Cam);
     // Here you might want to display some Handles
     */
 }
 
              This worked and I don't know why it has never been documented. It also seems more efficient than Render Texture method. Thanks so much.
This is an interesting approach @Bunny83 but I can only see the skybox not the cube I'm testing with. It's funny, but the cube displays in the camera preview but I only see the skybox in the render. Any advice?
Answer by RobAnthem · Dec 09, 2016 at 06:19 AM
You may also consider making a custom SceneView window, which is really simple, you just derive your window from SceneView instead of EditorWindow, then you can add a custom inspector and check for the specific window being focused to only work in your window, and with Handles, you can basically draw a custom GUI window in sceneview.
Your answer
 
             Follow this Question
Related Questions
Can't move GameObject in Scene view with Unity Components attached 2021.2.2f 0 Answers
Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer
Drawing to scene view from EditorWindow? 2 Answers
Set MinWidth for EditorWindow 1 Answer
Editor Window Views 0 Answers