Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Creating a totally custom scene editor in the editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by imaginaryhuman, Jan 4, 2012.

  1. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    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.
     
    Last edited: Jan 4, 2012
    ocimum likes this.
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    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?
     
    Last edited: Jan 4, 2012
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I have this working to use the Game View as a live interactive window...

    Code (csharp):
    1. @script ExecuteInEditMode()
    2.  
    3. function OnMouseDown () {
    4.     transform.position.x+=0.1; 
    5. }
    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)?
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Or is it possible to set up a camera and call Camera.Render() to render it in an EditorWindow?
     
  5. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    967
    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.
     
    ocimum likes this.
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    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.
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    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.
     
    IsDon and ocimum like this.
  8. silviosav

    silviosav

    Joined:
    Jun 28, 2012
    Posts:
    2
    Please can you specify how have you done it?
    I added to my custom Editor window this line in the Init function:
    Code (csharp):
    1. Handles.DrawCamera(Camera.mainCamera.pixelRect, Camera.mainCamera, DrawCameraMode.Normal);
    and
    Code (csharp):
    1. void Update()
    2.     {
    3.         Repaint(); 
    4.     }
    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?
     
    Last edited: Jun 28, 2012
  9. Paulo-Henrique025

    Paulo-Henrique025

    Joined:
    Dec 12, 2010
    Posts:
    230
    Looking forward to see how its done too.
     
  10. thesaint1987

    thesaint1987

    Joined:
    Jul 13, 2011
    Posts:
    168
    Why not do the inverse? Create your world with hitting play and then just save that state?!
     
  11. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    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() - http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow-autoRepaintOnSceneChange.html

    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?
    http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.Update.html
     
    Last edited: Nov 19, 2012