Is there a way to have a different Unity resolutions on iPhone 4 and 4S? Given that the 4 isn’t really powerful enough to run some of my game at retina resolution.
I think that I’ve read that it is not possible to change the resolution after the game initializes, so perhaps I need to modify the XCode project - any pointers or advice would be willingly received.
You need to modify AppController.mm
and check for an iPhone 4S in the CreateSurface code, changing the returned resolution if you discover that it is an iPhone4 or less:
bool CreateSurface(EAGLView *view, EAGLSurfaceDesc* surface)
{
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)surface->eaglLayer;
assert(eaglLayer == [view layer]);
CGSize newSize = [eaglLayer bounds].size;
newSize.width = roundf(newSize.width);
newSize.height = roundf(newSize.height);
#ifdef __IPHONE_4_0
int resolution = UnityGetTargetResolution();
// Start modification //
if([[machineName() substringWithRange:NSMakeRange(0, 6)] isEqualToString:@"iPhone"] && [[machineName() substringWithRange:NSMakeRange(6,1)] compare:@"4"] == NSOrderedAscending)
{
resolution = kTargetResolutionStandard;
}
// End modification //
if ( (resolution == kTargetResolutionNative || resolution == kTargetResolutionHD)
&& [view respondsToSelector:@selector(setContentScaleFactor:)]
&& [[UIScreen mainScreen] respondsToSelector:@selector(scale)]
)
{
CGFloat scaleFactor = [UIScreen mainScreen].scale;
[view setContentScaleFactor:scaleFactor];
newSize.width = roundf(newSize.width * scaleFactor);
newSize.height = roundf(newSize.height * scaleFactor);
UnitySetInputScaleFactor(scaleFactor);
}
#endif
surface->w = newSize.width;
surface->h = newSize.height;
UNITY_DBG_LOG ("CreateWindowSurface: FBO
");
CreateSurfaceGLES(surface);
GLES_CHK( glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->renderbuffer) );
QCARUnityPlayer::getInstance().QCARNotifyCreated((int)surface->w, (int)surface->h);
return true;
}
Then add this code to the top of the file:
#import <sys/utsname.h>
NSString*
machineName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}