Search Unity

Is there a way to Change button's focus position?Look this problem...

Discussion in 'Immediate Mode GUI (IMGUI)' started by milk, Apr 16, 2011.

  1. milk

    milk

    Joined:
    Apr 8, 2011
    Posts:
    3
    $focus.jpg View attachment $GUITest.unitypackage

    For some reason,I need a no title window(1024*768 similar full screen style),however, Unity cannot directly get, I try to use windowsAPI.
    Except the button's focus position,Everything looks good,the GUI-element's focus may offset.

    A good way to solve? Very grateful.
     
    Last edited: Apr 16, 2011
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Hello. Instead of having it be like this:

    Code (csharp):
    1.  function OnGUI() {
    2.  
    3. (GUI.Button(Rect(10,10,50,50), "Name"));
    4.        
    5. }
    Have it like this:

    Code (csharp):
    1.  
    2. var pos : Rect;
    3.  
    4.  function OnGUI() {
    5.  
    6. (GUI.Button (pos, "Name"));
    7.        
    8. }
    This way, you can edit the position and size of your button via the inspector. Have fun! :D
     
  3. milk

    milk

    Joined:
    Apr 8, 2011
    Posts:
    3
    Problems are not here, the problem is: the window after being resized,button position will change, but button's focus position will not change!
    For example:Assuming the origin in [0,0],the button at [800,600], the original window size is 800*600 ,press the button is ok
    After resized the window size is:1024*768, then press the button is invalid, it may press the point at [800,600]
     
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    What do you mean? It changes position based on resolution? If so, make the code i gave you this:

    Code (csharp):
    1. var pos : Rect;
    2. var nativeHorizontalResolution = 800.0;
    3. var nativeVerticalResolution = 600.0;
    4.  
    5.  function OnGUI() {
    6.   GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0), Quaternion.identity, Vector3(Screen.width / nativeHorizontalResolution, Screen.height / nativeVerticalResolution, 1));
    7.  
    8. (GUI.Button (pos, "Name"));
    9.        
    10. }
     
  5. milk

    milk

    Joined:
    Apr 8, 2011
    Posts:
    3