1

While designing UI in unity. If I directly attach single mdpi image and text in different resolution the images/sprite are scaling as per screen size.But the problem is when the image is scaled its getting displayed as pixelated?

So I read about asset bundle variants and trying to use them by making different bundles for different resolutions. (bundles varients are xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi and ldpi).

But I am stuck at how to pick the asset bundle variant for the device that my game is running.How to use Screen.dpi in unity to achieve that ?

I am assuming I can do the same for both Android(phones and Tabs) and IOS(iPhones and iPads) devices as well.

djkpA
  • 1,224
  • 2
  • 27
  • 57

1 Answers1

0

The table is following:

  • MDPI - 160dpi
  • HDPI - 240dpi
  • XHDPI - 320dpi
  • XXHDPI - 480dpi
  • XXXHDPI - 680dpi

So the check would be:

void Start(){
    if(Screen.dpi <= 160){
        //change your UI textures for mdpi
    }else if(Screen.dpi <= 240){
        //change your UI textures for hdpi
    }else if(Screen.dpi <= 320){
        //change your UI textures for xhdpi
    }else if(Screen.dpi <= 480){
        //change your UI textures for xxhdpi
    }else{
        //change your UI textures for xxxhdpi
    }
}

Edit: Be aware that maybe Unity changed shape of returned value. Play with it to see what's it's returning if this isn't correct. Also, see this and this.