Search Unity

One OnGUI() to control them all + smooth movement of groups

Discussion in 'Immediate Mode GUI (IMGUI)' started by yellowlabrador, Dec 17, 2007.

  1. yellowlabrador

    yellowlabrador

    Joined:
    Oct 20, 2005
    Posts:
    562
    Hello all,

    Is it safe to just have one OnGUI function?

    Code (csharp):
    1.  
    2. function OnGUI()
    3. {
    4.  //1st group of GUI
    5.  GUI.BeginGroup(Rect(..........
    6.  GUI.whatever over here......
    7.  GUI.EndGroup();
    8.  
    9. //2nd Group of GUI
    10.  GUI.BeginGroup(Rect(..........
    11.  GUI.whatever over here......
    12.  GUI.EndGroup();
    13.  
    14. //3rd Group of GUI
    15.  GUI.BeginGroup(Rect(..........
    16.  GUI.whatever over here......
    17.  GUI.EndGroup();
    18.  
    Also, I'm trying to smooth move a group by changing the groups Rect when a button is pressed, can I used .deltaTime to move the GUI groups somewhat slowy.?

    Thanks,
    Ray
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Yes, you can have everything inside one OnGUI function or split into separate ones... Up to you

    I'd recommend smoothing the movements in an Update function.
     
  3. yellowlabrador

    yellowlabrador

    Joined:
    Oct 20, 2005
    Posts:
    562
    Thanks Sir Nich.


    :D

    Ray
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Sir Nicholas - seems you've been knighted ;)

    The smoothing thing brings up a question- GUI.DragWindow exhibits some tearing even with we tell Unity to sync with the vertical refresh. If I understand correctly, the first OnGUI pass calculates the layout, and second draws the controls. Are Windows handled any differently, since they are contained in a separate function?