Tuesday, January 19, 2016

Change Resolution pixels of iOS Game using Unity3D 5.3.1f1 in Xcode 7.x

To change the resolution in Unity 5.3.1f1 is difficult in iOS when it comes to granularity of the device. Prior to 5.3.x, you could simply put in different modes for resolution. Auto Performance, Native Resolution, and Auto Quality were some of the few.  With the new version you can not adjust this so it requires that your hands get a bit dirty.

See below in DisplayManager.mm. look for UnityScreenScaleFactor:

Modify as below:

extern "C" float UnityScreenScaleFactor(UIScreen* screen)
{
// we should query nativeScale if available to get the true device resolution
// this way we avoid unnecessarily large frame buffers and downscaling.
// e.g. iPhone 6+ pretends to be a x3 device, while its physical screen is x2.6 something.
    
    /* Amit's custom code screen size */
    float resMult = 0.75f;
    switch(UnityDeviceGeneration())
    {
        case deviceiPadPro1Gen:     resMult = 0.6f;     break;
        case deviceiPhoneUnknown:   resMult = 0.75f;    break;
        case deviceiPhone6:         resMult = 0.75f; break;
        case deviceiPhone7:         resMult = 0.75f; break;
        case deviceiPhone6Plus:     resMult = 0.6f;     break;
        case deviceiPhone6S:        resMult = 0.75f; break;
        case deviceiPhone6SPlus:    resMult = 0.6f;     break;
        case deviceiPhone4:         resMult = 0.6f; break;
        case deviceiPad3Gen:        resMult = 0.5f; break;
        case deviceiPad4Gen:        resMult = 0.5f; break;
        case deviceiPadAir1:        resMult = 0.5f; break;
        case deviceiPadAir2:        resMult = 0.5f; break;
        case deviceiPadMini2Gen:    resMult = 0.5f; break;
        case deviceiPadMini3Gen:    resMult = 0.5f; break;
        case deviceiPadUnknown:     resMult = 0.5f;     break;
        default:                    resMult = 0.8f;     break;
    }

    if([screen respondsToSelector:@selector(nativeScale)])
{
// On AppleTV screen.nativeScale returns NaN when device is in sleep mode
if (isnan(screen.nativeScale))
return 1.0f;
else
return screen.nativeScale * resMult;
}
return screen.scale * resMult;

}


As you can see above, the resMult is what you multiply the resolution accordingly. For example if you take a 0.5f multiplyer on an iPad Retina (2048x1536) it'll turn your resolution to 1/2 or 0.5 of it which is essentially 1024x768.

Why you may ask would you want to do this? Speed, simply. Some games run entirely to slow in full resolution with Unity3D. It is optimal to use a multiplyer and scale down for older devices with AA or AAA games graphics.

No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...