Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GUI Resolution scale not working

Discussion in 'Immediate Mode GUI (IMGUI)' started by xema25, Aug 3, 2014.

  1. xema25

    xema25

    Joined:
    Aug 24, 2013
    Posts:
    37
    Hi!;) I've been googling this for a while but can't get it to work.

    I have an option to set my game in Fullscreen mode, the problem is that when I do that the GUI items (GUI TExts and GUI Textures) are anchored right, but the scale is the original.

    What I was doing is to call this...

    Vector2resizeRatio = newVector2((float)Screen.width / screenWidth, (float)Screen.height / screenHeight);
    GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, newVector3(resizeRatio.x, resizeRatio.y, 1.0f));

    //screenWidth and screenHeight is the original screen with I designed the GUI

    ... when I change the resolution by Screen.SetResolution (Screen.currentResolution.width, Screen.currentResolution.height, true); but nothing happens.


    Any idea?


    Thanks!
     
    Last edited: Aug 3, 2014
  2. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    Irony being what it is. The solution to your issue is part of the code I submitted when asking about a weird index increment issue I am seeing. To correctly scale for multi res in the gui use this code

    Code (CSharp):
    1.  scale.x = Screen.width/originalWidth; // calculate hor scale
    2.         scale.y = Screen.height/originalHeight; // calculate vert scale
    3.         scale.z = 1.0f;
    4.         int index = 0;
    5.         Matrix4x4 svMat = GUI.matrix; // save current matrix
    6.         // substitute matrix - only scale is altered from standard
    7.         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);