Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Questions about customizing the editor

Discussion in 'Scripting' started by ratamorph, Apr 2, 2009.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I'm very excited about the new editor scripting functionality, you can do a lot with it but there's still a few things I don't understand if I'm allowed to do or how.

    1. Can you modify a standard editor window? say change the behavior of the camera in the scene view, I was watching the Unite 08 opening keynote, and if I understand right Nicholas said he did the fps camera using the editor scripting api. If so how do I do it, can't seem to find it in the docs. I wanna try to add support for this http://forum.unity3d.com/viewtopic.php?t=6109

    2. Related to the first question, can I modify the popup menu that apears in the hierachy window? say I add a new option called create empty children? that creates an empty game object that's a children of the one highlited.

    3. How did Nicholas do the picture in picture looking window that would show the view of the currently selected camera? is it actually a part of the scene view window or is it a floating window?

    Any input would be greatly apreciated.
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Hi.

    I suggest you take a look at the FAQ in the UnityGUI section - that has a link to a new doc page about editor GUI scripting: http://unity3d.com/support/documentation/Components/gui-ExtendingEditor.html

    1) You can create new EditorWindows, custom inspectors and custom GUI inside the scene view. Supporting SpaceNavigator is gonna be hard at the moment, though.

    2) Yes - use the MenuItem property: http://unity3d.com/support/documentation/ScriptReference/MenuItem.html

    3) It was done with a custom inspector that had an OnSceneGUI which called Camera.Render on the target object.
     
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thanks for the quick reply, I've been reading the docs and doing some tests.

    I guess my first question would be how to make the windows, inspectors and such be a part of the scene view and not just floating dockable windows. And very similarely how do I access the popup menu in the hierachy? I followed the link and that explains me clearly how to create popup menus of my own or add them to the menu bar, but doesn't show me how to add them to an existing standard window like the hierachy.

    I'm guessing something like...
    Code (csharp):
    1.  
    2. @MenuItem ("Hierachy/Do Something")
    3. static function DoSomething () {
    4.     Debug.Log ("Perform operation");
    5. }
    6.  
    But that just a wild guess...

    I figure the reason adding space navigator support would be hard at the moment is because we don't get access to the scene view camera, am I right?

    Lastly is there a particular reason you used a custom inspector for the camera view window? My first guess would have been just to make a window.

    Thanks again for taking the time to answer my questions.
     
  4. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Ok just as I guessed

    Code (csharp):
    1.  
    2. @MenuItem ("Hierarchy/Do Something")
    3. static function DoSomething () {
    4.     Debug.Log ("Perform operation");
    5. }
    6.  
    Will just create a Hierarchy menu in the main menu which contains Do Something, What I want is the popup to appear when I right click an object in the Hierarchy. I tried CONTEXT/Hierarchy/Do Something (another wild guess) and that didn't seem to do anything.

    I also tried to do the custom inspector that shows the selected camera view in the scene view and runned into some issues.

    1. How do I make it so it doesn't override the camera inspector?, I just want this script to show me the view in the window for any camera that I select without having to add a script to every camera that I want to have this feature.
    Even without the OnInspectorGUI it will get rid of the camera component inspector UI.

    2. How do I make camera.Render() render inside the GUILayout area instead of the whole scene window?

    I could probably address both of this issues by attaching an extra custom inspector to my cameras that takes a render texture and draw that render texture inside my GUI, but I'd like to avoid that if possible.

    Here's what I did...

    Code (csharp):
    1.  
    2. @CustomEditor (Camera)
    3. class SelectedCameraViewScene extends Editor {
    4.    
    5.     function OnSceneGUI () {
    6.        
    7.         if(target.camera)
    8.         {
    9.             Handles.BeginGUI();
    10.             GUILayout.BeginArea(Rect(0,0,100,100));
    11.             GUILayout.Box(target.name);
    12.             target.camera.Render();
    13.                GUILayout.EndArea();
    14.             Handles.EndGUI();  
    15.         }
    16.     }
    17. }
    18.  
     
  5. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I haven't had time to read this all the way though, but "Camera.current" will return the current camera, which in the Editor is the scene view camera.

    You shouldn't have to add any scripts to your scene camera for this.

    Hope that helps,
    -Jeremy
     
  6. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
  7. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I wasn't aware Camera.current was the scene view camera on the editor, I just tried a simple script to move it and that doesn't seem to do anything, I wonder if that's why Nicholas said it would be hard to do, I wonder if its even possible.

    I'm trying to stay away from render textures, Nicholas said he did it using Camera.Render but that just renders over the whole scene view and not on my smaller box.

    Do you guys have any idea how to add an item to the context menu on hierarchy window? I've been browsing the docs and trying different things all day and can't seem to figure it out :cry:
     
  8. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    You set the camera's pixelRect before calling myCamera.Render in your GUI code (on the repaint event). Just remember that the camera's y origin is flipped from the GUI's representation.

    -Jeremy
     
  9. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Nice that's a lot better! now I need to figure out how to make my script not overwrite the Camera component inspector GUI.

    Is there a way to do this? I don't want to use another script to hook up my inspector to because I want this for all the cameras I use in the project.
     
  10. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I've posted my camera view scripts on the wiki http://www.unifycommunity.com/wiki/index.php?title=Camera_view_window , Ended up using a script that you attach to the cameras because that way you can switch on/off the feature for any camera aswell as modify the rectangle on the scenView.

    I'm open for any suggestions on how it can be improved.
     
  11. extragotcha

    extragotcha

    Joined:
    Mar 20, 2009
    Posts:
    42
    Still no luck with accessing the Hierarchy menuItem?
    I'm also interested in finding out how to do it.

    Any help would be more than welcome.
     
  12. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Still no luck, I'm guessing it can't be done at the moment, the docs are not clear on how this can be accomplished and doesn't seem like anyone has done it (atleast noone that wants to share an answer or reading this) so I gave up, wasted too much time trying to do so to the point that it was more productive to just add the item to the main menu and use a shortcut.

    If you find a way to do this please post it here or PM me, I'll post it in the wiki so everyone can do it.

    If anyone from UT read this, adding menu items to the context menu of the hierarchy or project view windows would be a very nice addition, and if we actually can do this please give us a snippet in the docs, in here or a sample project because we clearly can't figure this out ourselves :-(
     
  13. Cu3e

    Cu3e

    Joined:
    Oct 27, 2008
    Posts:
    63
    I do not know way to see the context menu hierarchy window. But you can see it in the Inspector. It is also possible to add them to your custom scripts (I guess since 2.5(?) because I found a thread where someone was asking for that...)

    http://unity3d.com/support/documentation/ScriptReference/MenuCommand-context.html

    will show as (see attachment)
     

    Attached Files:

  14. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thanks for the reply Tri

    I've also managed to modify the context menu in the inspector, but still haven't been able to modify the hierarchy one.

    The docs say
    But is the hierarchy panel an inspector?

    That's what has me thinking it might not be possible.
    Maybe if I could access the hierarchy window instance itself and access that menu somehow, but I've looked for such instance and haven't found it.
     
  15. yoyo

    yoyo

    Joined:
    Apr 16, 2010
    Posts:
    112
    UnityEditor includes an internal interface ICanHazCustomMenu, which gives an EditorWindow a chance to add custom menu items to the drop down menu in the upper right corner. Unfortunately this isn't accessible to us.
     
  16. fixitchris

    fixitchris

    Joined:
    Mar 16, 2011
    Posts:
    21