Dealing with Android resolutions
How I dealt with the fragmented resolutions of Android on Unity
Considering the android resolutions are so fragmented, I partly worked on a solution for dealing with it (This solution particularly works best for 2dToolkit, though I think the principle can be applied to others also). So rather than catering for resolution it is best to deal with the aspect ratios. So I listed down the possible aspect ratios along with some exceptions. Here is my list:
3:2
4:3
5:3
16:9
16:10
80:47
128:69
128:75
427:240
The last four of the ratios are for certain devices which are quite popular in most of the developing countries.
My code now determines first that to which particular ratio a device belongs using the following snippet.
bool AspectRatioIs(int width,int height)
{
if(Mathf.Abs((width - Camera.main.aspect*height)/height) <= 0.02f)
return true;
return false;
}
The above code determines to which particular aspect ratio we are dealing with. Now in your entry function you can simply write cases for each of the aspect ratio, for eg: I wrote in my Start() code for adjusting a particular button to a needed position.
About the Author(s)
You May Also Like