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

Resolution

Discussion in 'Editor & General Support' started by GameDevRick, Jun 3, 2012.

  1. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    Ok, I need help understanding what's going wrong here. I am trying to get this app that I am building
    on a PC to load on a Sony Tablet S which has a resolution of 1280 x 752 for the displayable area.
    I think that I don't understand the game window sizing or something, because I can't make the
    connection between it's size and the placement of the GUI elements. I need help because I am tired
    of uploading test builds to have someone else check for size and placement when I really just need
    to understand what is going wrong so I can fix it. Here is some of the code that I am using so you
    can see how I am approaching it and maybe tell me how to set things up so they appear properly
    on the target device:

    Code (csharp):
    1.  
    2. // I am creating this on a 1680x1050 monitor.
    3. // I am not sure how to set the game window to show things how they will appear on the target device
    4. // I tried free aspect with it set to 1280x752 and I have tried 16:10 ratio but neither come out right
    5.  
    6. // Native resolution metrics
    7. public static float native_width = 1280;
    8. public static float native_height = 752;  
    9.    
    10. // Target resolution metrics
    11. private int m_height;
    12. private int m_width;
    13.    
    14. // Resolution scaling factors
    15. float rx = Screen.width / native_width;
    16. float ry = Screen.height / native_height;
    17.  
    18. // This is the button that I am testing positioning with
    19. private Rect _ButtonRect = new Rect(Screen.width/2 + 400,Screen.height/2 + 200,198,147);
    20.  
    21. // START
    22. void Start () {    
    23.  
    24.     // Set Resolution
    25.     m_height = DisplayMetricsAndroid.HeightPixels;
    26.     m_width = DisplayMetricsAndroid.WidthPixels;
    27.        
    28.     Screen.SetResolution(m_height, m_width, false);
    29. }
    30.  
    31. // ON GUI
    32. void OnGUI() {
    33.  
    34.     GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1));
    35. }
    36.  
    Again, the goal is to be able to place my GUI elements on my game window as I want them to look
    on the tablet. I use the GUI scaling matrix to set them to the resolution of the target device. But, the
    screen is either squished or the GUI elements are out of place to the left and upwards. I really need
    an expert on this to get me squared away please.

    I think I need to get the game window set up to show exactly as they will appear on the target device.

    The build looks like this:
    http://www.mediafire.com/i/?7oqiu1ic0m3utkj

    But the result on the tablet looks like this:
    http://www.mediafire.com/i/?719ches2pcp5o01

    It seems to me that the device is at a lower resolution and the GUI are sizing to that,
    but when I adjust the resolution using these metrics :

    // Set Resolution
    m_height = DisplayMetricsAndroid.HeightPixels;
    m_width = DisplayMetricsAndroid.WidthPixels;

    // In the start method
    Screen.SetResolution(m_height, m_width, true);

    The entire screen gets squished like this:
    http://www.mediafire.com/i/?zc6x516ix82yxvy

    Can someone please explain what is going on here before I lose all my hair?
     
    Last edited: Jun 3, 2012
  2. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    Can anyone help me understand the relationship between the game window and what shows
    on the target device? I want to see what I have on my screen while I'm creating the game also
    on the device that I build it for. I am not making the connection.
     
    Last edited: Jun 3, 2012
  3. 1337GameDev

    1337GameDev

    Joined:
    Oct 31, 2011
    Posts:
    54
    If you select "free aspect" in drop down menu of editor window you can resize the editor. Then save the size when you get it right (you know by position guiTextures to edges of screen until they fit just right in editor window and also device). I could only get the width of my tablet im deploying to (1280) but not the height (800). Hope this helps a little bit.