Search Unity

Detecting phone type and adjusting Quality settings.

Discussion in 'iOS and tvOS' started by Tomo-Games, Sep 27, 2012.

  1. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Hi All

    I've been testing my game for iOS and Android and noticed that the iPhone 3GS won't cut the mustard with my game.

    Is there way to detect in-game which phone type is being used and to kick down the quality settings?

    I also appreciate any other tweaks that may help to get my draw calls down with older phones.
     
  2. Tricko

    Tricko

    Joined:
    Jul 11, 2012
    Posts:
    14
    This is how I've been doing it. The catch all at the end is because through different Unity versions I've had problems where it doesn't actually report the device type correctly, the later iPad 2 model I think was one.

    So my fallback was if I can't work out the exact device, look at the device family as assume it must be a newer model so go with the higher setting....

    Code (csharp):
    1. // Look for a device type.
    2.     var iOSGen = iPhone.generation;
    3.  
    4.     if (Debug.isDebugBuild) {
    5.         Debug.Log("iPhone.generation     : " + iPhone.generation);
    6.         Debug.Log("SystemInfo.deviceType : " + SystemInfo.deviceType);
    7.         Debug.Log("SystemInfo.deviceModel: " + SystemInfo.deviceModel);
    8.     }
    9.    
    10.     if (iOSGen == iPhoneGeneration.iPhone3GS) {
    11.         SetQualityLevel(2);
    12.     } else if (iOSGen == iPhoneGeneration.iPhone4) {
    13.         SetQualityLevel(3);
    14.     } else if (iOSGen == iPhoneGeneration.iPhone4S) {
    15.         SetQualityLevel(3);
    16.     } else if (iOSGen == iPhoneGeneration.iPad1Gen) {
    17.         SetQualityLevel(2);
    18.     } else if (iOSGen == iPhoneGeneration.iPad2Gen) {
    19.         SetQualityLevel(4);
    20.     } else if (iOSGen == iPhoneGeneration.iPad3Gen) {
    21.         SetQualityLevel(4);
    22.     } else if (iOSGen == iPhoneGeneration.iPodTouch3Gen) {
    23.         SetQualityLevel(3);    
    24.     } else if (iOSGen == iPhoneGeneration.iPodTouch4Gen) {
    25.         SetQualityLevel(3);    
    26.     } else {
    27.    
    28.         if (Debug.isDebugBuild) { Debug.LogWarning("Can't detect iOS device type."); }
    29.        
    30.         var device : String = SystemInfo.deviceModel;
    31.         if (device == "iPhone") {
    32.             if (Debug.isDebugBuild) { Debug.Log("Device type iPhone"); }
    33.             SetQualityLevel(4);
    34.  
    35.         } else if (device == "iPad") {
    36.             if (Debug.isDebugBuild) { Debug.Log("Device type iPad"); }
    37.             SetQualityLevel(4);
    38.            
    39.         } else if (device == "iPod") {
    40.             if (Debug.isDebugBuild) { Debug.Log("Device type iPod"); }
    41.             SetQualityLevel(3);
    42.         }                                      
    43.                                                                                        
    44.     }
    And then the bit of my SetQualityLevel function to actually change the quality setting itself you'll be interested in is this -

    Code (csharp):
    1. QualitySettings.SetQualityLevel(quality, true);
    Cheers.
     
    Last edited: Sep 27, 2012
  3. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Wow very nice. Exactly what I was looking for thanks !
     
  4. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Hmm there seems to be also a:
    Code (csharp):
    1. else if( iPhoneSettings.generation == iPhoneGeneration.iPhone3GS )
    This drives me crazy...

    And if you build for Android non of this code exists. I guess I'm gonna need some

    Code (csharp):
    1. #if UNITY_IPHONE
    2. #else
    3. #endif
    4.  
     
  5. Tricko

    Tricko

    Joined:
    Jul 11, 2012
    Posts:
    14
    Yeah, the iPhoneSettings.generation is depreciated I think, although I don't have a link to where I read that to back that up right now.

    It did take me ages of searching through other questions and examples before I settled on the iPhone.generation, although even then, it's not perfect as I don't really know how Unity is mapping the actual native device descriptions into those values - but it does mean you have to wait on Unity to update the enumerations - I've not checked if iPhone5 and iPad5 are actually supported in 3.5.6 yet.

    Next time around, I'll probably just bite the bullet and write my own native version to return the real strings and parse them directly myself - there's a perfect template of how to do it here - https://gist.github.com/1323251

    I wrote all of this before I had got my head around the right setup to make plugins work and accessible from Unityscript, and never bothered to add this into the one I ended up writing to detect iPod music playing, but one day I will :)

    And yes, all of my platform device and screen detection code is wrapped in big #if UNITY_IPHONE and #if UNITY_ANDROID statements, sorry I forgot to mention that!

    Cheers.
     
  6. Tomo-Games

    Tomo-Games

    Joined:
    Sep 20, 2010
    Posts:
    223
    Yeah I dread to know how to go about setting the quality list for Android devices... Too many devices out there.

    iPhone5 has been added to the enumerations list it appears . I hear the latest unity update allow the display to full screen (no black bars).
     
  7. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    I actually had to deal with this a little while ago, but I only had so many ways I could improve performance. What I did instead, was I had a frame rate counter, if it dropped below a certain number (i think it was 4 seconds at less than 20fps), I would degrade the quality (halve the particles, swap a shader).. But once it had degraded, it would never upgrade or check again.

    So, basically, the first five seconds of the game would determine the power of your phone, if it wasn't great, the quality would drop for performance reasons and that was the end of it. Not a fantastic solution but adding quality settings into the menu wasn't an option.