Creating a totally custom scene editor in the editor

I’d like to know if and how it’s possible to create a totally custom scene editor within the Unity editor.

My aim is to be able to add procedural geometry complete with textures/shaders to a scene and be able to click and interact with elements in realtime without having go to Play mode. I guess I just want some kind of generic rendering view or camera view which can show the scene as it would look in-game, and be able to deal with all the mouse and keyboard events.

So like, I’d have a custom EditorWindow, containing a camera which looks at a bunch of gameobjects/geometry, and lets you interact with it in whatever way I want. I do NOT want to use UnityGUI and I do NOT want to use gizmo’s. I want my own entirely custom user interface driven by events. Is this possible, and if so how is it done?

I guess what I’m basically asking for is the ability to render a camera within an EditorWindow, to show a scene, and to then use the mouse/keyboard to interact with it - as if a live preview of a game or whatever.

1 Like

What is the intended use of the draw all game view cameras command? Is it supposed to be used in an EditorWindow to implement a second Game view?

I have this working to use the Game View as a live interactive window…

@script ExecuteInEditMode()

function OnMouseDown () {
	transform.position.x+=0.1;	
}

But the object only updates/redraws/interacts following a modification to the object like changing the transform directly. I need to force the Game View to update every frame, how do I do that? I saw some method to do with setting things to Dirty somehow, but I see EditorUtility.SetDirty can only be run in an editor script, so how would I use that (or something else) to force the Game View to update after I click the mouse (or all the time)?

Or is it possible to set up a camera and call Camera.Render() to render it in an EditorWindow?

What I’ve done when I’ve played with procedural geometry is creating a custom inspector that only adds a button called “Instantiate”, that will call the function that instantiates the geometry and anything else into the current scene (usually a separate test scene). But it sounds like you are after something more? I must admit I don’t totally understand what you’re trying to do.

1 Like

Yes I have no problem creating the geometry, that’s not the issue really. It doesn’t matter so much what’s in the scene, just that I want to be able to see the scene like you see it in the Game window, without pressing play, and having various interactive graphical effects running. In a way, like Play mode but without being in play mode, and without having the default gizmos and user inputs present in the scene view.

As above, I either want to get control of the Game view, or get control of a custom camera view attached to a custom EditorWindow.

Support at Unity (following my email to them) gave me a great answer, which is to use Handles.DrawCamera() to draw a camera in a custom EditorWindow, set it to auto-update on scene changes, and then in the Update() function call a Repaint(). This works well, updating the custom view whenever there is OnGUI input, which would work well for most editors. At the moment I’m trying to figure out how to integrate this editor script with the rest of the non-editor-script parts, like via some globals or something.

2 Likes

Please can you specify how have you done it?
I added to my custom Editor window this line in the Init function:

Handles.DrawCamera(Camera.mainCamera.pixelRect, Camera.mainCamera, DrawCameraMode.Normal);

and

void Update()
	{
		Repaint();	
	}

But how can I set the auto-update on scene change?

And when you refer to OnGUI, are you talking about the gameObject on the Scene that I’ve initialized with the custom Editor window?

Can I have the same update of the custom view in the Game view?

Looking forward to see how its done too.

Why not do the inverse? Create your world with hitting play and then just save that state?!

Sorry, I didn’t realize anyone had replied to this thread. (And I’m a bit late, sorry)

The purpose of my question was to make a realtime updating camera view in the editor WITHOUT pressing play, so pressing play and saving changes is totally irrelevant

I don’t actually remember how I structured it, but it’s something I’m coming back to now for a new project. Setting auto-update on scene change is just a function call from EditorWindow.autoRepaintOnSceneChange() - Unity - Scripting API: EditorWindow.autoRepaintOnSceneChange

e.g.

EditorWindow editorWindow = GetWindow(typeof(CameraViewer));
editorWindow.autoRepaintOnSceneChange = true;
editorWindow.Show();

As far as OnGUI goes I think this all has to be done from an editor script stored in an Editor folder. You’ll have to use an editor script I think in order to receive the mouse inputs to your editor window.

I’m still figuring this out myself partly … I want full realtime updates and I think I found that either editor window updates were like half the speed/frames-per-second of the regular game window, or I just wasn’t doing it right.

This might help too… seems EditorWindow.Update() can call Repaint() to update at 100Hz?