Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to draw GUI elements outside of their Window?

Discussion in 'Extensions & OnGUI' started by kebrus, Sep 2, 2018.

  1. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    413
    I know this may sound unconventional, why would I want to draw anything outside a window, right? but for now I ask you to forget the purpose and just go along.

    I want to be able to call OnGUI and render the elements outside their given editor window. This is somewhat possible by setting RenderTexture.Active to a higher resolution render texture, the elements get rendered correctly to the render texture instead of the editor window. However, the elements are ALWAYS clipped at the original screen size. And this screen size is bound to your Screen resolution so resizing the editor window temporarily doesn't work either.

    Here's the simplest example I can think of:

    Code (CSharp):
    1.     RenderTexture rt; // Render texture in project 2000x2000
    2.     public void OnGUI()
    3.     {
    4.         RenderTexture cache = RenderTexture.active;
    5.  
    6.         RenderTexture.active = rt;
    7.         GUI.Button( new Rect( 0, 10, 2000, 20 ), "Test" );
    8.  
    9.         RenderTexture.active = cache;
    10.     }
    If the original editor window has a screen size of 1000x1000 then the button gets clipped at that point.

    I've been looking at the cs reference repo and trying different stuff by using reflection to be able to render outside the screen size, but nothing has worked so far. I'm guessing something is being done internally that even the cs reference doesn't show to clip them.

    Is this even possible?

    It's worth mentioning that using something like Graphics.DrawTexture works just fine, but there's more to drawing GUI elements than just textures.
     
    Last edited: Sep 2, 2018
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,242
    I gotta ask.... why oh why, not just use the new ui instead of OnGUI?
     
  3. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    413
    I wasn't explicit, sorry about that. This is for the editor, not for game UI. (gonna change the OP)
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,242
    Ahh ok. Well in that case I have long forgotten my OnGUI ways :p

    Good luck!
     
  5. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    455
    I'm surprised that you can get it working with DrawTexture at all. Can you post a snippet of what you used to test that? The GUIClip class is probably the most likely culprit, if you haven't looked into that yet.