Search Unity

scale GUI to the left

Discussion in 'Immediate Mode GUI (IMGUI)' started by CriTaG, Oct 20, 2011.

  1. CriTaG

    CriTaG

    Joined:
    Oct 4, 2011
    Posts:
    8
    Hi there,

    I have a question about scaling of the GUI box.

    On the left, I have four buttons, which will rescale when I have my mouse over it.
    Code (csharp):
    1.  
    2. if (_mouseOverCoursebutton)
    3.         {
    4.                 if (_boxCourse.width < buttonWidthBig)
    5.                     _boxCourse.width += 15;
    6.  
    7.                 if (_boxCourse.width >= buttonWidthBig)
    8.                 {
    9.                     _buttonCourseisBig = true;
    10.                 }
    11.         }
    12.         else
    13.             {
    14.                 if (_boxCourse.width > 100)
    15.                     _boxCourse.width -= 15;
    16.                 else _buttonCourseisBig = false;
    17.             }
    18.  
    The GUI will scale to a width of 205px with the expanding to the right.

    On the right side of the screen, I have four buttons that will also need to be rescaled.
    However, these buttons need to scale to the left.
    I tried the same code as shown above, with a change of the x position.

    For example, with the first resize of the button:
    Code (csharp):
    1.  
    2. _boxCourse.x -= _boxCourse.width/2;
    3.  
    Is there a way to scale the GUI to the left to twice it's size?
    Or do I need to dive into the GUI.Matrix (can't find any reference or info about it)?
     
    Last edited: Oct 20, 2011
  2. CriTaG

    CriTaG

    Joined:
    Oct 4, 2011
    Posts:
    8
    UPDATE: I fixed it with a not so clean way...
    Code (csharp):
    1.  
    2. pivotPoint = new Vector2(_boxDishes.x, _boxDishes.y + 50);
    3.             GUIUtility.RotateAroundPivot(180, pivotPoint);
    4.  
    5.             GUI.Box(_boxDishes, this.name.ToString(), dishesStyle);
    6.             if (_boxDishes.Contains(Event.current.mousePosition))
    7.             {
    8.                 _mouseOverDishesbutton = true;
    9.             }
    10.             else
    11.             {
    12.                 _mouseOverDishesbutton = false;
    13.                 _buttonDishesisBig = false;
    14.             }
    15.            
    16.             GUIUtility.RotateAroundPivot(180, pivotPoint);
    17.             if (_buttonDishesisBig)
    18.             {
    19.                 GUI.BeginGroup(new Rect(_boxDishes.x - 200, _boxDishes.y + 50, 100, 40));
    20.                 GUI.Button(new Rect(0, 0, 50, 40), "Cook");
    21.                 GUI.Button(new Rect(50, 0, 50, 40), "Fast");
    22.                 GUI.EndGroup();
    23.             }
    24.         }
    25.  
    It works for now, but perhaps someone has a better and cleaner way.