Search Unity

Is this the right way for resolution independent devices

Discussion in 'UGUI & TextMesh Pro' started by HappyLDE, Aug 21, 2014.

  1. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Hello, i want to have the button appear at decent size on the android/ios devices.

    Look at how i set the anchors. The button have text set to Best Fit so it gets bigger if the button is bigger.

    Is this the right way:

    ;)
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Probably not, in fact - I think what will happen this way is that the frames of elements will scale with screen sizes, but the actual font size will not, which is probably not what you want, because the text may become unreadably small on large screens.

    What you should use instead is the ReferenceResolution component. You attach it to the canvas, tell it what resolution you've built the the UI 'for', and it scales the entire thing up or down for other screen resolutions. The anchors then are just plain old unscaling anchor-to-center or whatever you like - you probably want to look at them more for dealing with different aspect ratios than for stuff like retina vs non-retina.

    Edit: oh I didn't read that you have the text set to Best Fit. The problem won't be *so* bad this way but you'll still have problems with e.g. scaling the graphics for your toggle.
     
  3. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Thank you for the answer, indeed i was afraid i didn't use the anchors at their true meaning. I will try to use the Reference Resolution component and play with it.

    Thanks!
     
  4. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    It works great!

    I reproduced the GUI from scratch using the Reference Resolution component on the Canvas and everything is now showing correctly on my android device as well!

    Normal anchors:


    Thanks!
     
    Tim-C likes this.
  5. Reda2

    Reda2

    Joined:
    Jul 25, 2014
    Posts:
    37
    I love you mate, I have been trying to do this all day, I can't believe it's that easy.
     
    superpig and Tim-C like this.
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    :) Glad to see you figured this out.